手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

iOS开发 UISegmentedControl的使用

时间:2024-10-13 12:46:52

1、创建工程项目和视图控制器 1、创建一个Sing View Application工程项目; 2、选中Main.storyboard进行编辑; 3、添加Navigation Controller并将箭头指向它; 4、将Navigation Controller的rootViewController指向View Controller。

iOS开发 UISegmentedControl的使用

2、创建UISegmentedControl 1、初始化:- (instancetype)initWithItems:(nullable NSArray *)items; 2、设置各种属性; 3、添加UISegmentedControl响应代理。

iOS开发 UISegmentedControl的使用

3、实现UISegmentedControl响应事件代理 - (void)segmentedControlAction:(UISegmentedControl *)segmentedControl;

iOS开发 UISegmentedControl的使用

4、将segmentedControl添加到navigationBar上 1、豹肉钕舞设置Frame: segmentedControl.frame = CGRectMake(x, y, width, height); 2、设置navigationItem.titleView为segmentedControl: self.navigationItem.titleView = segmentedControl;

iOS开发 UISegmentedControl的使用

5、运行效果图 1、插入了一个“插入分段”文本项; 2、插入了一个UIImage项; 3、删除了“分段3”项; 4、将下标为2的(“插入分段”项)的宽度改成为100.0,其他的平均; 5、将下标为2的(“插入分段”项)偏移y+5.0。

iOS开发 UISegmentedControl的使用

6、如果您喜欢,请按投票;如果有疑问,欢迎一起探讨。

iOS开发 UISegmentedControl的使用
© 手抄报圈