用xib自定義UIView並在代碼中使用--iOS


首先新建一個空的xib文件:

將size改為freedom:

然后在xib中自定義視圖(添加自己想要的其它視圖):

要寫好約束, 創建一個繼承uiview的類和他關聯,然后就可以調用了.

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//獲得nib視圖數組  
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"HeadView" owner:nil options:nil]; // Find the view among nib contents (not too hard assuming there is only one view in it).
// 得到最后一個view
HeadView *headView = [nibContents lastObject]; headView.frame = CGRectMake(0, 0, 300, 200); //headView.backgroundColor = [UIColor blueColor]; _tableView.tableHeaderView = headView; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM