Swift UITextView and segmented 代码生成操作

15. March 2016 Swift 0

var using:UISwitch!

override func viewDidLoad() {

super.viewDidLoad()

using = UISwitch()

let textview = UITextView(frame: CGRectMake(10, 100, 200, 100))//多行文本控件

textview.layer.borderWidth = 1

textview.layer.borderColor = UIColor.grayColor().CGColor //设置颜色

textview.editable = false //不可编辑

//开关控件的大小是确定的,

using.center = CGPointMake(100, 50)

using.on = true

using.addTarget(self, action: Selector(“swithdid”), forControlEvents: UIControlEvents.ValueChanged)

self.view.addSubview(using)

let items = [“1″,”2″,”3”]

var segmented = UISegmentedControl(items: items)

segmented.center = self.view.center

segmented.selectedSegmentIndex = 2

segmented.setTitle(“lijian”, forSegmentAtIndex: 3)

segmented.setImage(UIImage(named: <#T##String#>), forSegmentAtIndex: <#T##Int#>)

segmented.setContentOffset(CGSizeMake(10,7), forSegmentAtIndex:2)

segmented.insertSegmentWithImage(<#T##image: UIImage?##UIImage?#>, atIndex: <#T##Int#>, animated: <#T##Bool#>)

segmented.insertSegmentWithTitle(<#T##title: String?##String?#>, atIndex: <#T##Int#>, animated: <#T##Bool#>)

segmented.removeSegmentAtIndex(1, animated: true)

self.view.addSubview(segmented)

}

func swithdid(){

print(using.on

);

}


Leave a Reply

Your email address will not be published. Required fields are marked *