1. 程式人生 > >iOS-設定UITableViewCell之間的間距, 從xib中載入另一個xib

iOS-設定UITableViewCell之間的間距, 從xib中載入另一個xib

重新設定的UITableViewCellframe。

程式碼如下:

  1. #import "MyViewCell.h"

  2. @implementation MyViewCell

  3. - (void)awakeFromNib {

  4. [super awakeFromNib];

  5. // Initialization code

  6. }

  7. - (void)setFrame:(CGRect)frame{

  8. frame.origin.x += 10;

  9. frame.origin.y += 10;

  10. frame.size.height -= 10;

  11. frame.size.width -= 20;

  12. [super setFrame:frame];

  13. }

  14. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {

  15. [super setSelected:selected animated:animated];

  16. // Configure the view for the selected state

  17. }

  18. @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中是無法拖出線的