当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS实现选项卡效果的方法

iOS实现选项卡效果的方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

徐闻县第一中学,qvod金瓶梅,坐壁观宅斗

先来看看实现效果:

控件是如何使用的

添加lmjtabdelegate代理

lmjtab * tab = [[lmjtab alloc] initwithframe:cgrectmake(10, 50, 300, 30) linewidth:1 linecolor:[uicolor blackcolor]];
[tab setitemswithtitle:[nsarray arraywithobjects:@"选项一",@"选项二",@"选项三", nil] normalitemcolor:[uicolor whitecolor] selectitemcolor:[uicolor blackcolor] normaltitlecolor:[uicolor blackcolor] selecttitlecolor:[uicolor whitecolor] titletextsize:15 selectitemnumber:1];
tab.delegate   = self;
tab.layer.cornerradius = 5.0;
[self.view addsubview:tab];

代理函数

-(void)tab:(lmjtab *)tab didselecteditemnumber:(nsinteger)number{
 nslog(@"clicked:%ld",number);
}

lmjtab介绍:

@protocol lmjtabdelegate <nsobject>

-(void)tab:(lmjtab *)tab didselecteditemnumber:(nsinteger)number;

@end

@interface lmjtab : uiview

@property (nonatomic,assign) id<lmjtabdelegate>delegate;

/**
 * 控件初始化
 *
 * @param frame  控件的frame
 * @param linewidth 边线宽度
 * @param linecolor 边线颜色
 *
 * @return 控件实例
 */
-(id)initwithframe:(cgrect)frame linewidth:(cgfloat)linewidth linecolor:(uicolor *)linecolor;

/**
 * 设置选项卡的items
 *
 * @param titles  选项卡的标题数组
 * @param nitemcolor 正常选项的颜色
 * @param sitemcolor 选中选项的颜色
 * @param ntitlecolor 正常标题的颜色
 * @param stitlecolor 选中标题的颜色
 * @param size  标题大小
 * @param number  默认选中选项(取值范围:0 ~ ...)
*/
-(void)setitemswithtitle:(nsarray *)titles normalitemcolor:(uicolor *)nitemcolor selectitemcolor:(uicolor *)sitemcolor normaltitlecolor:(uicolor *)ntitlecolor selecttitlecolor:(uicolor *)stitlecolor titletextsize:(cgfloat)size selectitemnumber:(nsinteger)number;

@end

总结

以上就是这篇文章的全部内容了,希望能对各位ios开发者们有所帮助,如果有疑问大家可以留言交流。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网