ios 写枚举
2014-04-02 18:35
288 查看
.h文件中。。。
typedef NS_OPTIONS(NSUInteger, LoginOrReg_phone) { //NSUInteger枚举类型,LoginOrReg_phone枚举名称
loginPhoneType = 0, // 登录的状态
regPhoneType = 1 // 注册的状态
};
申明一个属性
@property LoginOrReg_phone loginOrReg_phone;
.m文件中。。。用switch 进行分类
switch (_loginOrReg_phone) {
caseloginPhoneType:
{
UILabel *asd = [[UILabelalloc]initWithFrame:CGRectMake(14.0f,registered.bottom+25.0f/2,SCREEN_WIDTH-28,
25)];
[asd setBackgroundColor:[UIColorredColor]];
[self.viewaddSubview:asd];
}
break;
caseregPhoneType:
{
RTLabel *state = [[RTLabelalloc] //RTLabel的使用
initWithFrame:CGRectMake(10.0f,registered.bottom+20.0f/2
, SCREEN_WIDTH-2, 30)];
[self.viewaddSubview:state];
NSString *text =@"<font color='#999999'>点击上面的 “注册”按钮,
即表示你同意“聚汇”的<font color='#0D6396'><a href='http://www.baidu.com'>服务条款</a></font>和<font color='#0D6396'><a href='http://www.sina.com'>隐私政策</a></font></font>";
state.delegate =
self;
[state setText:text];
}
break;
default:
break;
}
#pragma mark RTLabel点击链接地址
-(void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSString *)url
{
}
在同一个tableView中使用两种风格的cell
cell.h 文件中。。。。
typedef enum {
CellTypeGroup, //好友分组
CellTypeFriend, //好友
}CellType;
//-------------------------分组-----------------------
@property (strong,nonatomic)
UILabel *groupName; //分组名称
@property (strong,nonatomic)
UILabel *groupDesc; //分组描述
//-------------------------好友-----------------------
@property (strong,nonatomic)
SelectButton *selectButton;
@property (strong,nonatomic)
UILabel *friendName; //好友名称
@property (strong,nonatomic)
UIImageView *stateImage; //状态
//初始化方法
-(id)initWithCellType:(CellType)type reuseIdentifier:(NSString *)reuseIdentifier;
.m文件中。————————
-(id)initWithCellType:(CellType)type reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:reuseIdentifier]) {
int cell_width = 300;
if (IOS_DEVICE >=
7) {
cell_width = 320;
}
//------好友分组单元格------
if (type == CellTypeGroup)
{
//分组名称
self.groupName = [[UILabel
alloc]initWithFrame:CGRectMake(LEFTMARGIN,
10, 0 , 0)];
self.groupName.backgroundColor = [UIColor
clearColor];
self.groupName.font = [UIFont
systemFontOfSize:FONT_SIZE_FTN];
//字体大小
[self.contentView
addSubview:self.grou
4000
pName];
//分组描述
self.groupDesc = [[UILabel
alloc]initWithFrame:CGRectMake(LEFTMARGIN,
35, 200 , 25)];
self.groupDesc.backgroundColor = [UIColor
clearColor];
self.groupDesc.textColor = [UIColor
grayColor]; //字体颜色
self.groupDesc.font = [UIFont
systemFontOfSize:FONT_SIZE_TWE];
//字体大小
[self.contentView
addSubview:self.groupDesc];
}
//---------好友单元格---------
else if (type ==
CellTypeFriend)
{
//创建选择按钮
self.selectButton = [[SelectButton
alloc]initWithFrame:CGRectMake(260,
15, 30, 30)];
self.selectButton.tag =
1;
self.selectButton.hidden =
YES;
[self.contentView
addSubview:self.selectButton];
//好友状态
self.stateImage = [[UIImageView
alloc]initWithFrame:CGRectMake(self.headImage.frame.size.width-20,
0, 20, 20)];
[self.headImage
addSubview:self.stateImage];
//好友名称
self.friendName = [[UILabel
alloc]initWithFrame:CGRectMake(LEFTMARGIN,
10, 0 , 0)];
self.friendName.backgroundColor = [UIColor
clearColor];
self.friendName.font = [UIFont
systemFontOfSize:FONT_SIZE_FTN];
//字体大小
[self.contentView
addSubview:self.friendName];
}
self.type = type;
}
return self;
}
在Controller.m中使用
#pragma mark-定制cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//设置cell类型
CellType type;
static NSString *cellIndef;
if (indexPath.section ==
0) {
type = CellTypeGroup;
cellIndef = @"1";
}
if (groupArr.count ==
0) {
type = CellTypeFriend;
cellIndef = @"3";
}
//创建自定义cell
FriendCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellIndef];
if (!cell) {
cell = [[FriendCell
alloc]initWithCellType:type reuseIdentifier:cellIndef];
cell.delegate = self;
}
//新的朋友and未分组好友
if (indexPath.section ==
0 && type == CellTypeGroup) {
cell.groupName.text =
name[indexPath.row];
//获取分组名称
[cell.groupName sizeToFit];
//分组名Label自适应大小
cell.groupDesc.text =
desc[indexPath.row];
//获取分组描述
}
//好友-第二分组
if (type == CellTypeFriend) {
NSString *key = keyArr[indexPath.section];
NSArray *persons = [PersonDict
objectForKey:key];
[cell writePersonModel:person];
}
return cell;
}
typedef NS_OPTIONS(NSUInteger, LoginOrReg_phone) { //NSUInteger枚举类型,LoginOrReg_phone枚举名称
loginPhoneType = 0, // 登录的状态
regPhoneType = 1 // 注册的状态
};
申明一个属性
@property LoginOrReg_phone loginOrReg_phone;
.m文件中。。。用switch 进行分类
switch (_loginOrReg_phone) {
caseloginPhoneType:
{
UILabel *asd = [[UILabelalloc]initWithFrame:CGRectMake(14.0f,registered.bottom+25.0f/2,SCREEN_WIDTH-28,
25)];
[asd setBackgroundColor:[UIColorredColor]];
[self.viewaddSubview:asd];
}
break;
caseregPhoneType:
{
RTLabel *state = [[RTLabelalloc] //RTLabel的使用
initWithFrame:CGRectMake(10.0f,registered.bottom+20.0f/2
, SCREEN_WIDTH-2, 30)];
[self.viewaddSubview:state];
NSString *text =@"<font color='#999999'>点击上面的 “注册”按钮,
即表示你同意“聚汇”的<font color='#0D6396'><a href='http://www.baidu.com'>服务条款</a></font>和<font color='#0D6396'><a href='http://www.sina.com'>隐私政策</a></font></font>";
state.delegate =
self;
[state setText:text];
}
break;
default:
break;
}
#pragma mark RTLabel点击链接地址
-(void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSString *)url
{
}
在同一个tableView中使用两种风格的cell
cell.h 文件中。。。。
typedef enum {
CellTypeGroup, //好友分组
CellTypeFriend, //好友
}CellType;
//-------------------------分组-----------------------
@property (strong,nonatomic)
UILabel *groupName; //分组名称
@property (strong,nonatomic)
UILabel *groupDesc; //分组描述
//-------------------------好友-----------------------
@property (strong,nonatomic)
SelectButton *selectButton;
@property (strong,nonatomic)
UILabel *friendName; //好友名称
@property (strong,nonatomic)
UIImageView *stateImage; //状态
//初始化方法
-(id)initWithCellType:(CellType)type reuseIdentifier:(NSString *)reuseIdentifier;
.m文件中。————————
-(id)initWithCellType:(CellType)type reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:reuseIdentifier]) {
int cell_width = 300;
if (IOS_DEVICE >=
7) {
cell_width = 320;
}
//------好友分组单元格------
if (type == CellTypeGroup)
{
//分组名称
self.groupName = [[UILabel
alloc]initWithFrame:CGRectMake(LEFTMARGIN,
10, 0 , 0)];
self.groupName.backgroundColor = [UIColor
clearColor];
self.groupName.font = [UIFont
systemFontOfSize:FONT_SIZE_FTN];
//字体大小
[self.contentView
addSubview:self.grou
4000
pName];
//分组描述
self.groupDesc = [[UILabel
alloc]initWithFrame:CGRectMake(LEFTMARGIN,
35, 200 , 25)];
self.groupDesc.backgroundColor = [UIColor
clearColor];
self.groupDesc.textColor = [UIColor
grayColor]; //字体颜色
self.groupDesc.font = [UIFont
systemFontOfSize:FONT_SIZE_TWE];
//字体大小
[self.contentView
addSubview:self.groupDesc];
}
//---------好友单元格---------
else if (type ==
CellTypeFriend)
{
//创建选择按钮
self.selectButton = [[SelectButton
alloc]initWithFrame:CGRectMake(260,
15, 30, 30)];
self.selectButton.tag =
1;
self.selectButton.hidden =
YES;
[self.contentView
addSubview:self.selectButton];
//好友状态
self.stateImage = [[UIImageView
alloc]initWithFrame:CGRectMake(self.headImage.frame.size.width-20,
0, 20, 20)];
[self.headImage
addSubview:self.stateImage];
//好友名称
self.friendName = [[UILabel
alloc]initWithFrame:CGRectMake(LEFTMARGIN,
10, 0 , 0)];
self.friendName.backgroundColor = [UIColor
clearColor];
self.friendName.font = [UIFont
systemFontOfSize:FONT_SIZE_FTN];
//字体大小
[self.contentView
addSubview:self.friendName];
}
self.type = type;
}
return self;
}
在Controller.m中使用
#pragma mark-定制cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//设置cell类型
CellType type;
static NSString *cellIndef;
if (indexPath.section ==
0) {
type = CellTypeGroup;
cellIndef = @"1";
}
if (groupArr.count ==
0) {
type = CellTypeFriend;
cellIndef = @"3";
}
//创建自定义cell
FriendCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellIndef];
if (!cell) {
cell = [[FriendCell
alloc]initWithCellType:type reuseIdentifier:cellIndef];
cell.delegate = self;
}
//新的朋友and未分组好友
if (indexPath.section ==
0 && type == CellTypeGroup) {
cell.groupName.text =
name[indexPath.row];
//获取分组名称
[cell.groupName sizeToFit];
//分组名Label自适应大小
cell.groupDesc.text =
desc[indexPath.row];
//获取分组描述
}
//好友-第二分组
if (type == CellTypeFriend) {
NSString *key = keyArr[indexPath.section];
NSArray *persons = [PersonDict
objectForKey:key];
[cell writePersonModel:person];
}
return cell;
}
相关文章推荐
- 学习iOS开发的第21天
- IOS字符串Format可以对数值四舍五入
- iOS GCD的使用
- ios drawRect绘制图形
- 基础类的DSP/BIOS API调用
- viewController中的IOS 5之后新加的五个函数 willMoveToParentViewController
- ios--OpenCV--标记姿态的模拟
- ios 7 statusbar 状态栏 跟随navigationbar的颜色而改变
- ios--OpenCV--人脸检测(初级)
- ios--OpenCV--标记检测(中级)
- IOS 构造和使用TableView(基于storyboard) (三)附件的使用
- iOS中使用DTCoreText显示emoji表情问题
- ios--OpenCV--标记检测(初级)
- ios--OpenCV--视频捕获Camera
- ios--OpenCV--AR可视化
- IOS中NSUserDefaults的用法
- iOS/iPhone 程序文件目录结构以及启动流程
- iOS/iPhone 程序文件目录结构以及启动流程
- iOS应用IAP设置总结
- ios编码过程中的崩溃保护解决方案 VDM