iOS開發項目篇—49“發現”介面完善

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   strong   

iOS開發項目篇—49“發現”介面完善

一、簡單說明

已經完成的效果:-----》目標效果

      

需要完善的地方:

(1)子標題和標題顯示在同一行上。

修改樣式:UITableViewCellStyleSubtitle---》UITableViewCellStyleValue1

 1 //初始化類方法 2 +(instancetype)cellWithTablView:(UITableView *)tableView 3 { 4     static NSString *ID=@"ID"; 5     YYCommonCell *cell=[tableView dequeueReusableCellWithIdentifier:ID]; 6     if (cell==nil) { 7 //       cell = [[YYCommonCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; 8        cell = [[YYCommonCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID]; 9     }10     return cell;11 }

(2)設定標題和子標題的文字

設定標題字型為黑色粗體,設定子標題為12號字型。

 1 // 2 //  YYCommonCell.m 3  4 -(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 5 { 6     self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]; 7     if (self) { 8         //設定標題和子標題的文字 9         self.textLabel.font=[UIFont boldSystemFontOfSize:15];10         self.detailTextLabel.font=[UIFont systemFontOfSize:12];11     }12     return self;13 }

調整後的效果:

(3)調整子標題的文字緊跟在標題的後面顯示,而不是靠右對齊。

 1 // 2 //  YYCommonCell.m 3  4 #pragma mark-調整子控制項的位置 5 -(void)layoutSubviews 6 { 7     [super layoutSubviews]; 8     //調整子標題的x值 9     self.detailTextLabel.x=CGRectGetMaxX(self.textLabel.frame)+10;10 }

(4)設定tableView的背景色,調整組間的間距。

設定每一組的頭部和尾部的高度

實現代碼:

 1 - (void)viewDidLoad 2 { 3     [super viewDidLoad]; 4      5     //建立並添加一個搜尋方塊 6     //添加一個搜尋方塊 7     YYSearchBar *searchBar=[YYSearchBar SearchBar]; 8     searchBar.frame=CGRectMake(0, 100, 300, 35); 9     self.navigationItem.titleView=searchBar;10     11     //設定tableview的屬性12     //設定全域背景色13     self.tableView.backgroundColor=YYGlobalBg;14     self.tableView.sectionFooterHeight=0;15     self.tableView.sectionHeaderHeight=YYStatusCellMargin;16     17 18     // 初始化模型資料19     [self setupGroups];20 }

此時的顯示效果:

(5)第一個cell的距離。

第一種做法:在自訂的cell中,讓每個cell的y值都網上挪一段距離。

1 -(void)setFrame:(CGRect)frame2 {3     frame.origin.y-=30;4     [super setFrame:frame];5 }

列印查看tableView在控制器中的frame

 1 - (void)viewDidLoad 2 { 3     [super viewDidLoad]; 4      5     //建立並添加一個搜尋方塊 6     //添加一個搜尋方塊 7     YYSearchBar *searchBar=[YYSearchBar SearchBar]; 8     searchBar.frame=CGRectMake(0, 100, 300, 35); 9     self.navigationItem.titleView=searchBar;10     11     //設定tableview的屬性12     //設定全域背景色13     self.tableView.backgroundColor=YYGlobalBg;14     self.tableView.sectionFooterHeight=0;15     self.tableView.sectionHeaderHeight=YYStatusCellMargin;16     17     // 初始化模型資料18     [self setupGroups];19     20     YYLog(@"viewDidLoad---%@",NSStringFromUIEdgeInsets(self.tableView.contentInset));21 }22 23 -(void)viewDidAppear:(BOOL)animated24 {25     [super viewDidAppear:animated];26     YYLog(@"viewDidAppear---%@",NSStringFromUIEdgeInsets(self.tableView.contentInset));27 }

距離上方的導覽列和下方的工具條永遠有64和49的距離。

查看第一個cell的位置

-(void)setFrame:(CGRect)frame{//    frame.origin.y-=30;    YYLog(@"%f",self.y);    [super setFrame:frame];}

列印查看

cell的原始高度為35.

第二種做法

 1 - (void)viewDidLoad 2 { 3     [super viewDidLoad]; 4      5     //建立並添加一個搜尋方塊 6     //添加一個搜尋方塊 7     YYSearchBar *searchBar=[YYSearchBar SearchBar]; 8     searchBar.frame=CGRectMake(0, 100, 300, 35); 9     self.navigationItem.titleView=searchBar;10     11     //設定tableview的屬性12     //設定全域背景色13     self.tableView.backgroundColor=YYGlobalBg;14     self.tableView.sectionFooterHeight=0;15     self.tableView.sectionHeaderHeight=YYStatusCellMargin;16     17     // 初始化模型資料18     [self setupGroups];19     20     YYLog(@"viewDidLoad---%@",NSStringFromUIEdgeInsets(self.tableView.contentInset));21     self.tableView.contentInset=UIEdgeInsetsMake(YYStatusCellMargin-35, 0, 0, 0);22 }

最終效果:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.