控件
来源:互联网 发布:中国为什么封闭网络 编辑:程序博客网 时间:2024/04/28 14:17
一、Label
<span style="font-size:18px;"><span style="font-size:18px;">UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; label.backgroundColor = [UIColor redColor]; label.text = @"文字 这是文字啊,长沙,湖南中国"; //63, 130, 139 = (r, g, b) label.textColor = [UIColor colorWithRed:63/255.0 green:130/255.0 blue:139/255.0 alpha:1]; label.font = [UIFont systemFontOfSize:24]; //文字的阴影设置 label.shadowColor = [UIColor yellowColor]; label.shadowOffset = CGSizeMake(10, -20); //文本的对齐方式 label.textAlignment = NSTextAlignmentRight; //右对齐 label.lineBreakMode = NSLineBreakByTruncatingMiddle; //如果显示不了就省略中间部分 label.numberOfLines = 0;//0表示自动调节行数 [self.view addSubview:label]; NSLog(@"%@", [UIFont fontNamesForFamilyName:@"Zapfino"]);</span></span>相对而言,label比较简单一点。主要的属性有text,backgroundColor,font,text Color等。
二、view
<span style="font-size:18px;"><span style="font-size:18px;"> UIView *colorview=[[UIView alloc]init]; colorview.frame=CGRectMake(0, 50, 100, 200); colorview.backgroundColor=[UIColor redColor]; [self.view addSubview:colorview]; UIView *greenView=[[UIView alloc]init]; greenView.frame=CGRectMake(100, 50, 100, 200); greenView.backgroundColor=[UIColor greenColor]; [self.view addSubview:greenView];//red与green平齐 // [colorview addSubview:greenView]; UIView *blueview=[[UIView alloc]initWithFrame:CGRectMake(100, 0, 100, 200)];//相对坐标 blueview.backgroundColor=[UIColor blueColor]; [greenView addSubview:blueview];//bule在green之上</span></span>view也相对比较简单,值得注意的是显示时
[self.view addSubview:colorview];//现实在view之上。
[greenView addSubview:blueview]; //现实bule在green之上。
三、image/imageview
<span style="font-size:18px;"> UIImage *image11 = [UIImage imageNamed:@"1.png"];//类调用类方法 UIImage *image22 = [UIImage imageNamed:@"2.png"]; UIImageView *imageView1 = [[UIImageView alloc] init];//实例化对象 imageView1.image = image11; imageView1.highlightedImage = image22; imageView1.highlighted = NO;//NO //显示位置和大小 imageView1.frame = CGRectMake(50, 250, 200, 200); [self.view addSubview:imageView1]; UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]; UIImage *image0 = [UIImage imageNamed:@"1.png"]; UIImage *image1 = [UIImage imageNamed:@"2.png"]; UIImage *image2 = [UIImage imageNamed:@"3.png"]; UIImage *image3 = [UIImage imageNamed:@"4.png"]; UIImage *image5 = [UIImage imageNamed:@"6.png"]; //创建一个OC的数组,并且设置它里面的元素 NSArray *array = [NSArray arrayWithObjects:image0, image1, image2, image3, image5,nil]; //背景图片 imageView2.image = image0; //动画执行的时长,单位为秒 imageView2.animationDuration = 3; //动画图片数组 imageView2.animationImages = array; //重复次数,默认为无限循环 imageView2.animationRepeatCount = 3; //开始执行动画 [imageView2 startAnimating]; [self.view addSubview:imageView2];</span>
<span style="font-size:18px;"><span style="white-space:pre"></span>UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.tiff"<span style="white-space:pre"></span>]];//初始化,设置背景图片 imageView1.frame = CGRectMake(0, 0, 320, 480); NSMutableArray *array1 = [NSMutableArray array];//NUMytableArray可变数组 //类方法调用属性 for (int i = 1; i <= 61; i++) { NSString *str = [NSString stringWithFormat:@"%d.tiff", i];//字符串才有给i赋值的属性 UIImage *image = [UIImage imageNamed:str]; [array1 addObject:image];//此处比较特殊,需要注意 } imageView1.animationImages = array1; imageView1.animationDuration = 3;//播放时间 imageView1.animationRepeatCount = 4;//循环次数 [self.view addSubview:imageView1];</span>image和imageview一般是在一起使用。image的作用只是用来存放图片没有其他属性比如坐标,大小,背景等都没有,
唯一值得注意的是它有两个状态一个是普通状态,一个是高亮状态。
imageview是用来显示图片它拥有相对较多的属性显示多张图片时有两种方法一种是一张一张赋给image,另外一种是使用for循环,两者有较大的区别需要注意。
四、UIbutton
1、系统提供
UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeSystem];
btn.frame=CGRectMake(200,64, 100, 40);
[btn setTitle:@"按钮"forState:UIControlStateNormal];
btn.backgroundColor=[UIColorgreenColor];
[btn addTarget:selfaction:@selector(didclicked1:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:btn];
2、用户自定义按钮UIButton *musicButton=[UIButtonbuttonWithType:UIButtonTypeCustom];
musicButton.frame=CGRectMake(220,400, 67, 53);
[musicButton setImage:[UIImageimageNamed:@"b"]forState:UIControlStateNormal];
//按钮按下去是高亮状态
[musicButton setImage:[UIImageimageNamed:@"a"]forState:UIControlStateHighlighted];
[musicButton addTarget:selfaction:@selector(didpalymusic:) forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:musicButton];
3、用代码实现点击-(void)didpalymusic:(UIButton *)sender
{
AudioServicesPlayAlertSound(musicID); //结合用户自定义按钮中倒数第二句构成
}
五、UIViewController(视图控制器)
1、自己写的viewcontrol类也可以实例一个对象,如果该类上面有按钮或label则对象上也有相应控件
2、UIViewController实例的对象不能设置坐标和大小,它总是充满屏幕。
六、UINavigationController(导航控制器)
//初始化导航控制器
UINavigationController *navControl=[[UINavigationControlleralloc]initWithRootViewController:viewControl];
//将一个新的页面在导航栈中显示出来,入栈、压栈
//所有已经在导航控制器管理下的页面(UIViewController)都可以通过一个navigationController的属性访问它所在的导航控制器
[self.navigationControllerpushViewController:viewControl3 animated:YES];
//放回到导航控制器的上一个页面
[self.navigationControllerpopViewControllerAnimated:YES];
- 控件
- 控件
- 控件
- 控件
- 控件
- 控件
- 控件
- 控件
- 控件
- 控件
- 控件
- 控件
- *****控件****
- 控件
- 控件
- 控件
- 控件
- 控件
- java多线程通信(管道通信)
- css样式,锁定表头,只在IE浏览器下可以使用,没有兼容性
- maven仓库信息分析站点推荐
- 3101: N皇后
- leedcode做题总结,题目Path SumI/II-------- 2012/10/13-14
- 控件
- ARM体系中存储系统
- HDU 1051: Wooden Sticks(贪心)
- hdu 4613 Points( KMP 图形学)
- 关于DSP C6727外部中断的用法
- Codeforces 3A Shortest Path of the King
- Windows 下正则表达式库 re2 在 C++ 和 Python 中的编译和使用
- swift菜鸟入门视频教程-11-方法
- Lua学习笔记(三)——协同程序