UI常用控件的一些属性

UILable

 1  //设置文本信息
 2     nameLable.text = @"用户名:";  3 //对齐方式(居中 居左 局右);  4 nameLable.textAlignment = NSTextAlignmentRight;  5 //设置文本内容颜色  6 nameLable.textColor = [UIColor blackColor];  7 //设置文本字体  8 nameLable.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];  9 //打印所有字体样式 10 NSLog(@"%@",[UIFont familyNames]); 11 //设置行数 12 nameLable.numberOfLines = 0; 13 //断行模式 14 nameLable.lineBreakMode = NSLineBreakByWordWrapping;//按照单词换行 15 //阴影颜色 16 nameLable.shadowColor = [UIColor blueColor]; 17 //阴影大小 18 nameLable.shadowOffset = CGSizeMake(2, 1);

 

UITextField

 1     //背景颜色
 2     textField.backgroundColor = [UIColor greenColor];  3 //文本内容  4 textField.text = @"用户名";  5 //设置文本内容颜色  6 textField.textColor = [UIColor redColor];  7 //文本对齐方式  8 textField.textAlignment = NSTextAlignmentCenter;  9 //边框样式 10 textField.borderStyle = UITextBorderStyleRoundedRect; 11 //设置占位符 12 textField.placeholder = @"请输入用户名"; 13 //是否允许编辑 14 textField.enabled = YES; 15 //开始编辑时是否清空输入框 16 textField.clearsOnBeginEditing = YES; 17 //是否安全输入 18 textField.secureTextEntry = YES; 19 //设置键盘样式 20 textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; 22 textField.returnKeyType = UIReturnKeySearch; 23 //自定义视图 24 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 414, 100)]; 25 view.backgroundColor = [UIColor cyanColor]; 26 // textField.inputView = view; 27 //输入框上边的内容 28 textField.inputAccessoryView = view; 29 //清除按钮模式(x) 30 textField.clearButtonMode = UITextFieldViewModeWhileEditing; 32 [textField becomeFirstResponder];//成为第一响应者

 

UIButton

1  button.frame = CGRectMake(50, 100, 300, 300); 2 button.backgroundColor = [UIColor orangeColor]; 3 //设置标题 普通状态下 4 [button setTitle:@"点 我" forState:UIControlStateNormal]; 5 //高亮状态下 (点住的时候) 6 [button setTitle:@"谁点我" forState:UIControlStateHighlighted]; 7 //设置标题颜色 8 button.tintColor = [UIColor whiteColor];

 1 //添加事件 2 3 [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; 

 

UIPageControl

 1 self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, 636, 214, 40)];  3 self.page.backgroundColor = [UIColor grayColor];  4 // 设置小圆点个数  5 self.page.numberOfPages = 4;  7 // 设置当前显示的页数  8 self.page.currentPage = 2; 10 // 设置未选中的圆点颜色 11 self.page.pageIndicatorTintColor = [UIColor greenColor]; 12 // 设置选中的圆点颜色 13 self.page.currentPageIndicatorTintColor = [UIColor redColor]; 15  [self.page addTarget:self action:@selector(fangfang:) forControlEvents:UIControlEventValueChanged]; 16 [self.view addSubview:self.page];

 

UISegmentControl

 1 // 创建对象
 2     self.segment = [[UISegmentedControl alloc] initWithItems:@[@"女神", @"男神", @"屌丝"]];  4 // 设置属性  5 self.segment.backgroundColor = [UIColor orangeColor];  6 self.segment.frame = CGRectMake(50, 100, 300, 50);  8 // 指定被选中的分段  9 self.segment.selectedSegmentIndex = 0; 10 // 样式颜色 11 self.segment.tintColor = [UIColor redColor]; 12 //设置标题 13 [self.segment setTitle:@"阿福" forSegmentAtIndex:2];

 

UISlider

 1 // 1.创建对象
 2     self.mySlider = [[UISlider alloc] initWithFrame:CGRectMake(7, 50, 400, 40)];  3  4 // 2.设置属性  5 self.mySlider.backgroundColor = [UIColor blackColor];  6 // 设置slider的最小值  7 self.mySlider.minimumValue = 0;  8 // 设置slider的最大值  9 self.mySlider.maximumValue = 10; 14 // 设置按钮颜色 15 self.mySlider.thumbTintColor = [UIColor redColor]; 17 // 设置划过区域的颜色 18 self.mySlider.minimumTrackTintColor = [UIColor yellowColor]; 19 // 设置未划过区域的颜色 20 self.mySlider.maximumTrackTintColor = [UIColor orangeColor];

 

UISwitch

 1 // 1.创建对象
 2     // 设置frame只有(X.Y)起作用,size使用系统默认大小  3 UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(300, 100, 100, 100)];  4 // 2.设置属性  5 switchButton.backgroundColor = [UIColor blackColor];  6 // 设置开关样式的颜色  7 switchButton.tintColor = [UIColor redColor];  8 // 设置开启时的颜色  9 switchButton.onTintColor = [UIColor blueColor]; 10 // 设置开关按钮的颜色 11 switchButton.thumbTintColor = [UIColor cyanColor]; 12 //设置程序运行之后开关的状态(开启还是关闭) 13 [switchButton setOn:YES animated:YES];

 

UIScorllView

 1  / * *
 2      *  第一步:将scrollView添加到rootView上,使视图可以滚动
 3      */
 5     self.scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
 6     self.scrollView.backgroundColor = [UIColor cyanColor];
 7     [self addSubview:self.scrollView];
 9     /**
10      *  第二步:将需要滚动的图片添加到scrollView上
11      */
13     self.myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"111"]];
14     // UIImageView不设置frame时候默认使用图片大小
16     [self.scrollView addSubview:self.myImageView];     
19    // 设置滚动范围
20     self.scrollView.contentSize = self.myImageView.frame.size;   
22     // 设置是否显示水平滚动条
23     self.scrollView.showsHorizontalScrollIndicator = NO;
24     // 设置是否显示垂直方向滚动条
25     self.scrollView.showsVerticalScrollIndicator = NO;     
27     // 设置是否回弹
28     self.scrollView.bounces = YES;

 

 1 // 设置水平方向滚动
 2     self.scrollView.contentSize = CGSizeMake(self.myImageView.frame.size.width, 0);  4 // 设置垂直方向滚动  5 self.scrollView.contentSize = CGSizeMake(0, self.myImageView.frame.size.height);  8 // 设置偏移量,规定要显示的位置  9 self.scrollView.contentOffset = CGPointMake(400, 100); 12 // 设置缩放 13 // 设置最小的缩放比例 14 self.scrollView.minimumZoomScale = 0.1; 15 // 设置最大的缩放比例 16 self.scrollView.maximumZoomScale = 2;
 

转载于:https://www.cnblogs.com/crazygeek/p/5562367.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值