let segment = UISegmentedControl(frame: CGRectMake(10.0,10.0,(CGRectGetWIDth(self.vIEw.bounds) - 10.0 * 2),40.0))self.vIEw.addSubvIEw(segment) segment.background@R_404_6004@ = UI@R_404_6004@.lightGray@R_404_6004@()
// 设置按钮(图标样式)segment.insertSegmentWithImage(UIImage(named: "image01"),atIndex: 0,animated: true)segment.insertSegmentWithImage(UIImage(named: "image02"),atIndex: 1,animated: true)segment.insertSegmentWithImage(UIImage(named: "image03"),atIndex: 2,animated: true)segment.insertSegmentWithImage(UIImage(named: "image04"),atIndex: 3,animated: true)segment.insertSegmentWithImage(UIImage(named: "image05"),atIndex: 4,animated: true)// 移除按钮segment.removeAllSegments() // 设置按钮(标题样式)segment.insertSegmentWithTitle("红色",animated: true)segment.insertSegmentWithTitle("绿色",animated: true)segment.insertSegmentWithTitle("白色",animated: true)segment.insertSegmentWithTitle("橙色",animated: true)segment.insertSegmentWithTitle("segmentControl",animated: true) segment.insertSegmentWithImage(UIImage(named: "image05"),atIndex: 5,animated: true)
// 设置某个按钮宽度segment.setWIDth(110.0,forSegmentAtIndex: 4) // 设置某个按钮不可用segment.setEnabled(false,forSegmentAtIndex: 4)segment.setEnabled(true,forSegmentAtIndex: 5) // 设置后没有选中高亮效果,默认falsesegment.momentary = false // 初始化选中按钮,默认0segment.selectedSegmentIndex = 1 // 按钮边框及字体颜色segment.tint@R_404_6004@ = UI@R_404_6004@.green@R_404_6004@()// 响应事件segment.addTarget(self,action: Selector("segmentValueChange:"),forControlEvents: UIControlEvents.ValueChanged)
总结
以上是内存溢出为你收集整理的swift中UISegmentController的使用全部内容,希望文章能够帮你解决swift中UISegmentController的使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)