UISwitch开关按钮
var uiswtich:UISwitch!;
uiswtich =UISwitch();
uiswtich.center =CGPointMake(100,50);
uiswtich.on =true;
uiswtich.addTarget(self, action:Selector("switchDidChange"), forControlEvents:UIControlEvents.ValueChanged);
self.view.addSubview(uiswtich);
func switchDidChange()
{
println(uiswtich.on);//打印值为true或false
}
UITextField文本框
var textField =UITextField(frame: CGRectMake(10, 160, 200, 30));
textField.borderStyle =UITextBorderStyle.RoundedRect;//文本框样式为圆角
textField.placeholder ="请输入";//提示信息
textField.textAlignment =NSTextAlignment.Center;//文字在文本框中问位置
textField.becomeFirstResponder();//自动打开键盘
textField.returnKeyType =UIReturnKeyType.Done;//键盘上的return按钮更换为Done
textField.clearButtonMode =UITextFieldViewMode.WhileEditing;//清楚文本框按钮
textField.backgroundColor =UIColor.blueColor();//文本框背景颜色
textField.delegate =self;//return按钮的触发事件
self.view.addSubview(textField);
return的触发事件需要重写textFieldShouldReturn,重写需要继承UITextFieldDelegate
func textFieldShouldReturn(textField:UITextField) -> Bool {
textField.resignFirstResponder();//关闭键盘
println(textField.text);//打印文本框内的内容
return true;
}
UITextView多文本框
var textView =UITextView(frame: CGRectMake(50, 300, 200, 100));
textView.layer.borderWidth =1;//边框宽度
textView.layer.borderColor =UIColor.grayColor().CGColor;
textView.dataDetectorTypes =UIDataDetectorTypes.All;//电话,网址自动加跳转
textView.allowsEditingTextAttributes =true;//对文字进行加粗等操作
textView.editable =false;
self.view.addSubview(textView);
UISegmentedControl选择控件
var items = ["one","two","three"];
var segmented = UISegmentedControl(items: items);
segmented.center =self.view.center;
// segmented.tintColor = UIColor.redColor();
segmented.selectedSegmentIndex =1;//默认选择
segmented.addTarget(self, action:"segmentedDIdChange:", forControlEvents: UIControlEvents.ValueChanged);
self.view.addSubview(segmented);
func segmentedDIdChange(segmented:UISegmentedControl)
{
println(segmented.selectedSegmentIndex)//打印索引
println(segmented.titleForSegmentAtIndex(segmented.selectedSegmentIndex));//打印内容
}
这四个控件还有其他的属性,就不一一写出来了,基本上要用的时候找一下就可以