iOS-設定UITableViewCell之間的間距, 從xib中載入另一個xib
重新設定的UITableViewCellframe。
程式碼如下:
-
#import "MyViewCell.h"
-
@implementation MyViewCell
-
- (void)awakeFromNib {
-
[super awakeFromNib];
-
// Initialization code
-
}
-
- (void)setFrame:(CGRect)frame{
-
frame.origin.x += 10;
-
frame.origin.y += 10;
-
frame.size.height -= 10;
-
frame.size.width -= 20;
-
[super setFrame:frame];
-
}
-
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
-
[super setSelected:selected animated:animated];
-
// Configure the view for the selected state
-
}
-
@end
效果如下:
看小夥伴的程式碼,發現一個寫的很好的東西 , 先說場景 , 我自己封好了一個顯示9宮格圖片的View (NineImageView),並且使用了xib來設定了約束 ,NineImageView.xib中的UIView關聯為NineImageView , 現在想在cell中也需要使用這個9宮格的view .
方法1 : 在cell中新增一個普通的UIView 取名 為midView , 然後在cell的awakeFormNib中,使用 self.midView addSubView的方式新增9宮格view .
方法2 : 直接在cell中設定一個view為NineImageView, 然後取消NineImageView.xib中UIView與NineImageView的關聯, 在NineImageView.m中重寫initWithCoder方法 , 完成載入 . 注意 , 類的關聯只能有一個 , 比如在cell中的一個view關聯為NineImageView,那麼NineImageView.xib的View關聯一定要取消掉,同時存在2個關聯會出錯的.
還有在NineImageView.xib中設定下 file's Owner 為NineImageView , 不然從NineImageView.xib中是無法拖出線的