IOS7(新UI之自定义UITableViewCell)
来源:互联网 发布:捡宝贝淘宝u站 编辑:程序博客网 时间:2024/05/19 03:23
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/
0 0
- IOS7(新UI之自定义UITableViewCell)
- IOS7学习之路一(新UI之自定义UITableViewCell)
- IOS7 UI新变化
- iOS7 新UI 一
- iOS7 新UI 二
- iOS7 新UI 三
- iOS7 新UI 四
- Snail—UI学习之UITableView之自定义UITableViewCell
- IOS7开发~新UI学起(一)
- IOS7开发~新UI学起(二)
- IOS7开发~新UI学起(三)
- IOS7开发~新UI学起(四)
- IOS7开发~新UI学起(一)
- IOS7开发~新UI学起(二)
- IOS7开发~新UI学起(三)
- IOS7开发~新UI学起(四)
- UITableView之(五):自定义UITableViewCell
- Swift之自定义UITableViewCell
- LeetCode OJ Merge k Sorted Lists
- mybatis报错java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
- UVa 10375 - Choose and divide
- 显隐转换,虚成员和抽象成员
- LeetCode OJ Remove Nth Node From End of List
- IOS7(新UI之自定义UITableViewCell)
- LeetCode OJ Rotate List
- UVa 10491 - Cows and Cars
- Javaweb学习笔记2—Tomcat和http协议
- hdu 4407 Sum (容斥原理)
- Arch Linux 简易打包指南
- Maven学习记录---徐小兵blog
- 《从0到1》读书笔记第10章“打造帮派文化”第1记: PayPal黑帮花名册
- JAVA 语言客户信息管理系统解题报告