ios7 新升級之後界面有了很大的變化,xcode模擬器去掉了手機邊框和home鍵,如果想回到主頁面,可以按住shift+comment+r鍵。廢話少說先展示一下新UI下UItableView設置爲Group後的效果:
整體界面顯得更加簡潔,而且UITableViewCell的寬度默認爲滿屛,也取消了圓角。
下面說下自定義UITableView的過程:
首先在storyboard中給cell拖過來一個UIimageView和兩個label
然後新建一個MyCell類繼承自UITableViewCell。
MyCell代碼:
- // MyCell.h
- // XcodeTest
- //
- // Created by wildcat on 13-11-7.
- // Copyright (c) 2013年 wildcat. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- @interface MyCell : UITableViewCell
- @property (weak, nonatomic) IBOutlet UIImageView *myImageView;
- @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
- @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
- @end
- // MyCell.m
- // XcodeTest
- //
- // Created by wildcat on 13-11-7.
- // Copyright (c) 2013年 wildcat. All rights reserved.
- //
- #import "MyCell.h"
- @implementation MyCell
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- // Initialization code
- }
- return self;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated
- {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- #pragma mark 設置Cell的邊框寬度
- - (void)setFrame:(CGRect)frame {
- frame.origin.x += 10;
- frame.size.width -= 22 * 10;
- [super setFrame:frame];
- }
- @end
使用:
在UITableViewController中使用,代碼如下:
- //
- // RootViewController.m
- // XcodeTest
- //
- // Created by wildcat on 13-11-7.
- // Copyright (c) 2013年 wildcat. All rights reserved.
- //
- #import "RootViewController.h"
- #import "MyCell.h"
- @interface RootViewController ()
- @end
- @implementation RootViewController
- - (id)initWithStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 3;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- if (cell==nil) {
- cell=[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- cell.nameLabel.text=@"WildCat";
- cell.timeLabel.text=@"2013-11-7";
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 75.f;
- }
- @end
修改後的效果:
當然如果你喜歡cell滿屏的效果,你完全可以不設cell的寬度。。。
轉載請註明:版權所有http://1.wildcat.sinaapp.com/