IOS中对控件的操作
2013-12-11 19:20
253 查看
将一个图片作为视图的背景代码如下:
- (void)addImageView
{
//找到图片
UIImage *pImage=[UIImage
imageNamed:@"sea.png"];
//根据内容图片创建ImageView
self.pImageView = [[UIImageView
alloc] initWithImage:pImage];
//将ImageView放到父视图中
[self.view
insertSubview:self.pImageView
atIndex:0];
}
对Label的操作代码如下
- (void)addLabel
{
//创建一个Label
UILabel *pLabel=[[UILabel
alloc] initWithFrame:CGRectMake(10,
10, 120,
50)];
//内容
pLabel.text=@"HelloWorld\nSecondLine";
//设置字体和大小
pLabel.textAlignment=NSTextAlignmentCenter;
//字体颜色
pLabel.textColor=[UIColor
redColor];
//显示行数
pLabel.numberOfLines=
2;
//阴影颜色
pLabel.shadowColor=[UIColor
blackColor];
//阴影尺寸
pLabel.shadowOffset =
CGSizeMake(2.0,
1.0);
//设置label的背景为透明色
pLabel.backgroundColor=[UIColor
clearColor];
[self.view
addSubview:pLabel];
[pLabel
release];
}
文本框的操作代码如下:
- (void)addTextField
{
//创建TextField
UITextField *pTextField=[[UITextField
alloc] initWithFrame:CGRectMake(10,
116, 200,
31)];
//设置边框样式
pTextField.borderStyle =
UITextBorderStyleRoundedRect;
//设置字体
pTextField.font = [UIFont
systemFontOfSize:18.0];
//根据宽度改变字体
pTextField.adjustsFontSizeToFitWidth =
YES;
//最小字体
pTextField.minimumFontSize =
2.0;
//清除按钮的样式
pTextField.clearButtonMode =
UITextFieldViewModeWhileEditing;
//弹出键盘的样式
pTextField.keyboardType =
UIKeyboardTypeDefault;
//设置使用自动更正功能
pTextField.autocorrectionType=
UITextAutocorrectionTypeNo;
//设置键盘自动大小写的属性
pTextField.autocapitalizationType =
UITextAutocapitalizationTypeNone;
//设置返回按钮的类型
pTextField.returnKeyType =
UIReturnKeyDone;
//设置是否支持密码文本显示
pTextField.secureTextEntry =
YES;
//设置委托
pTextField.delegate =
self;
[self.view
addSubview:pTextField];
[pTextField
release];
}
按钮的操作代码如下:
//控制控件
- (void)addButton
{
//创建一个按钮
UIButton *pBtn = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
//设置区域
[pBtn
setFrame:CGRectMake(10,
70, 100,
40)];
[pBtn setTitle:@"Normal"
forState:UIControlStateNormal];
[pBtn setTitle:@"HighLight"
forState:UIControlStateHighlighted];
//允许显示高亮
pBtn.showsTouchWhenHighlighted =
YES;
[pBtn addTarget:self
action:@selector(buttonDown:)
forControlEvents:UIControlEventTouchDown];
[pBtn addTarget:self
action:@selector(buttonRelease:)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:pBtn];
}
- (void)addImageView
{
//找到图片
UIImage *pImage=[UIImage
imageNamed:@"sea.png"];
//根据内容图片创建ImageView
self.pImageView = [[UIImageView
alloc] initWithImage:pImage];
//将ImageView放到父视图中
[self.view
insertSubview:self.pImageView
atIndex:0];
}
对Label的操作代码如下
- (void)addLabel
{
//创建一个Label
UILabel *pLabel=[[UILabel
alloc] initWithFrame:CGRectMake(10,
10, 120,
50)];
//内容
pLabel.text=@"HelloWorld\nSecondLine";
//设置字体和大小
pLabel.textAlignment=NSTextAlignmentCenter;
//字体颜色
pLabel.textColor=[UIColor
redColor];
//显示行数
pLabel.numberOfLines=
2;
//阴影颜色
pLabel.shadowColor=[UIColor
blackColor];
//阴影尺寸
pLabel.shadowOffset =
CGSizeMake(2.0,
1.0);
//设置label的背景为透明色
pLabel.backgroundColor=[UIColor
clearColor];
[self.view
addSubview:pLabel];
[pLabel
release];
}
文本框的操作代码如下:
- (void)addTextField
{
//创建TextField
UITextField *pTextField=[[UITextField
alloc] initWithFrame:CGRectMake(10,
116, 200,
31)];
//设置边框样式
pTextField.borderStyle =
UITextBorderStyleRoundedRect;
//设置字体
pTextField.font = [UIFont
systemFontOfSize:18.0];
//根据宽度改变字体
pTextField.adjustsFontSizeToFitWidth =
YES;
//最小字体
pTextField.minimumFontSize =
2.0;
//清除按钮的样式
pTextField.clearButtonMode =
UITextFieldViewModeWhileEditing;
//弹出键盘的样式
pTextField.keyboardType =
UIKeyboardTypeDefault;
//设置使用自动更正功能
pTextField.autocorrectionType=
UITextAutocorrectionTypeNo;
//设置键盘自动大小写的属性
pTextField.autocapitalizationType =
UITextAutocapitalizationTypeNone;
//设置返回按钮的类型
pTextField.returnKeyType =
UIReturnKeyDone;
//设置是否支持密码文本显示
pTextField.secureTextEntry =
YES;
//设置委托
pTextField.delegate =
self;
[self.view
addSubview:pTextField];
[pTextField
release];
}
按钮的操作代码如下:
//控制控件
- (void)addButton
{
//创建一个按钮
UIButton *pBtn = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
//设置区域
[pBtn
setFrame:CGRectMake(10,
70, 100,
40)];
[pBtn setTitle:@"Normal"
forState:UIControlStateNormal];
[pBtn setTitle:@"HighLight"
forState:UIControlStateHighlighted];
//允许显示高亮
pBtn.showsTouchWhenHighlighted =
YES;
[pBtn addTarget:self
action:@selector(buttonDown:)
forControlEvents:UIControlEventTouchDown];
[pBtn addTarget:self
action:@selector(buttonRelease:)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:pBtn];
}
相关文章推荐
- IOS控件 动画操作 与 CALayer 简单操作
- iOS开发-UI控件:UIImagePickerController 视频录制操作,视频大小,时间长度
- IOS控件 动画操作 与 CALayer 简单操作
- iOS开发中UIImageView控件的常用操作整理
- ios自动化 ——AutomatorX ATX 文档 - iOS 控件操作 API
- IOS开发笔记-01按钮操作-11.UI控件概述
- iOS应用开发中的文字选中操作控件UITextView用法讲解
- iOS应用开发中的文字选中操作控件UITextView用法讲解
- ios开关和滑块控件操作学习
- iOS开发UI篇—自定义瀑布流控件(蘑菇街数据刷新操作)
- 从0到1搭建移动App功能自动化测试平台(2):操作iOS应用的控件
- ios switch 控件基本操作
- ios开发分页控件的相关操作
- iOS开发UI篇—自定义瀑布流控件(蘑菇街数据刷新操作)
- [iOS开发项目-3] 按钮控件的移动,放大缩小,左右旋转操作
- ios开发操作分页控件的方法
- iOS多线程编程中,子线程如何访问和操作主线程UI中的视图控件(下载操作用子线程实现)
- iOS开发UI篇—自定义瀑布流控件(蘑菇街数据刷新操作)
- iOS动画 基本动画操作和长按控件抖动
- <iOS>关于子线程和block中操作主线程界面的控件讨论