UILabel UISwitch UISegmentedControl UIAlertView
基础小控件
/***************************************UIlabel*************************************/
UILabel *label = [[UILabel alloc]init];//创建UIlabel对象
label.frame = CGRectMake(50, 50, 100, 50);//设定label的位置与大小
label.backgroundColor = [UIColoryellowColor];//设定label的背景颜色
label.text = @"123";//给label添加文本
label.tag = 1;//设置label标签,便于以后使用
label.textAlignment = NSTextAlignmentRight;//设置文本对齐方式,系统默认为字体居右
label.textColor = [UIColorblackColor];//设置字体的颜色
label.numberOfLines = 0;//设置文本的行数,0代表有无线行
[label.layersetCornerRadius:10.0];//设置label边框角为圆角,后面数值为圆角的半径
label.font = [UIFontsystemFontOfSize:15];//设置字体的大小
label.adjustsFontSizeToFitWidth = YES;//设置字体大小根据label的大小自动调整
[self.view addSubview:label];//显示label
/***************************************UIlabel*************************************/
/****************************************UISwitch***********************************/
UISwitch *sw = [[UISwitchalloc]init];
sw.frame = CGRectMake(150, 150, 100, 100);//设置位置和大小,发现大小无效。即开关控件大小不受影响
sw.on = YES;//设置开关的状态(开/关)
sw.onImage=[UIImageimageNamed:@"1.png"];//无效
sw.offImage=[UIImageimageNamed:@"logo.png"];//无效,即UISwitch上不能添加图片
[sw addTarget:selfaction:@selector(loop) forControlEvents:UIControlEventValueChanged];//绑定监听方法
[self.view addSubview:sw];//显示sw
/****************************************UISwitch***********************************/
/***************************************UISegmentControl****************************/
UISegmentedControl *seg = [[UISegmentedControlalloc]initWithItems:@[@"",@"",@""]];//初始化seg,并且给seg分段
seg.frame = CGRectMake(50, 200, 200, 50);//设置seg的位置与大小
seg.backgroundColor = [UIColorwhiteColor];//设置seg的背景颜色
[seg setTitle:@"登录"forSegmentAtIndex:0];//给莫一段设置标题
//[seg setImage:[UIImage imageNamed:@"lun"] forSegmentAtIndex:1];//必须添加背景为透明的图片
[seg insertSegmentWithTitle:@"2"atIndex:1animated:YES];//在原有的基础上添加一段,可以设置该段所放的位置与标题
unsigned long int i = seg.numberOfSegments;//获得seg的总段数
NSLog(@"段数%zi",i);
NSString *s = [seg titleForSegmentAtIndex:2];//获得某一段的标题
NSLog(@"标题%@",s);
UIImage *image = [seg imageForSegmentAtIndex:1];//获得某一段的图片
NSLog(@"图片%@",image);
[seg setWidth:60forSegmentAtIndex:1];//设置某一段的宽度
[seg setEnabled:NO];//激活seg
[seg setEnabled:NOforSegmentAtIndex:2];//激活某一段,yes为激活
seg.selectedSegmentIndex = 2;//设置默认选中项
[seg setBackgroundImage:[UIImageimageNamed:@"lun"] forState:UIControlStateNormalbarMetrics:UIBarMetricsDefault];
[seg addTarget:selfaction:@selector(loop1:) forControlEvents:UIControlEventTouchUpInside];//seg的监听事件
[self.view addSubview:seg];
/***************************************UISegmentControl****************************/
/***************************************UIAlertView********************************/
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"是否注册"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:@"取消", nil];
[alert show];
/***************************************UIAlertView********************************/
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld",(long)buttonIndex);
}//UIAlertView的监听事件
UILabel UISwitch UISegmentedControl UIAlertView的更多相关文章
- ios 延迟调用 && UIImageView && UILabel && UISegmentedControl && UISwitch && UISlider
// // ViewController.m // UI_Lesson3 // // Created by archerzz on 15/8/13. // Copyright (c) 2015 ...
- 【IOS 开发】基本 UI 控件详解 (UISegmentedControl | UIImageView | UIProgressView | UISlider | UIAlertView )
转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50163725 一. 分段控件 (UISegmentedControl) 控件展 ...
- UI中一些不常用的控件UIActivityIndicatorView、UIProgressView、UISegmentedControl、UIStepper、UISwitch、UITextView、UIAlertController
//UIActivityIndicatorView //小菊花,加载 #import "ActivityIndicatorVC.h" @interface ActivityIndi ...
- UISwitch(开关控件)、UISegmentedControl(分段控件)
一.UISwitch 1.初始化 UISwitch *s1 = [[UISwitch alloc]initWithFrame:CGRectMake(50, 170, 100, 200)]; 2.设 ...
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- UI-不常用控件 UIActivityIndicatorView、UIProgressView、UISegmentedControl、UIStepper、UISwitch、UITextView、UIAlertController
1 //UIActivityIndicatorView //小菊花,加载================================================================ ...
- iphone:自定义UIAlertView
由于项目中有这样一个需求:需要在保存是弹出框选择保存的地点.选择UIAlertView来实现,但是要在UIAlertView中增加UISwitch的控件,这就需要自定义一个继承UIAlertView的 ...
- ##DAY2 UILabel、UITextField、UIButton、UIImageView、UISlider
##DAY2 UILabel.UITextField.UIButton.UIImageView.UISlider #pragma mark ———————UILabel——————————— UILa ...
- 自定义一个类似UIAlertView的弹出框
这个是和UIAlertView类似,但是可以自定义view的样式废话不多说,上代码: 首先第一步:创建一个继承自View的类如: #import <UIKit/UIKit.h> @clas ...
随机推荐
- 【Alpha版本】冲刺阶段——Day 5
我说的都队 031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬 ...
- jax-ws开发总结
服务端开发步骤: 1.定义SEI,即java中的接口 2.定义SEI的实现类,使用@webservice注解标记它是一个webservice服务类 3.发布服务 客户端开发步骤:使用jdk的servi ...
- Linux_cheat命令安装和使用
1.安装python yum -y install python 2.安装epel源.安装pip yum install epel-release -y yum install python ...
- mysql-查询一天,一周,一月,一年,以及mysql的基本日期函数
查询一天: select * from table where to_days(column_time) = to_days(now()); select * from table where dat ...
- git初体验(七)多账户的使用
多github帐号的SSH key切换 我有两个github帐号,一个是个人所用,一个是为公司项目所用.如果是单用户(single-user),很方便,默认拿id_rsa与你的github服务器的公钥 ...
- SurfaceView, TextureView, SurfaceTexture等的区别
SurfaceView, GLSurfaceView, SurfaceTexture以及TextureView是Android当中名字比较绕,关系又比较密切的几个类.本文基于Android 5.0(L ...
- Python开发最常犯错误总结10种
不管是在学习还是工作过程中,人都会犯错.虽然Python的语法简单.灵活,但也一样存在一些不小的坑,一不小心,初学者和资深Python程序员都有可能会栽跟头.本文是Toptal网站的程序员梳理的10大 ...
- Web前端性能优化教程08:配置ETag
本文是Web前端性能优化系列文章中的第五篇,主要讲述内容:配置ETag.完整教程可查看:Web前端性能优化 什么是ETag? 实体标签(EntityTag)是唯一标识了一个组件的一个特定版本的字符串, ...
- 多线程中的synchronized
synchronized是Java中的关键字,是一种同步锁.它修饰的对象有以下几种: 1. 修饰一个代码块,被修饰的代码块称为同步语句块,其作用的范围是大括号{}括起来的代码,作用的对象是调用这个代码 ...
- perl push an array to hash
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array=qw /fm1 fm2 fm3 fm4 fm5 fm6/; ...