iOS中UILabel和UIButton的自定义设置
来源:互联网 发布:纽约爱乐 知乎 编辑:程序博客网 时间:2024/06/03 18:09
这是使用empty application 创建的工程,这里主要是在 didFinshLaunchingWithoptions:方法中操作。
#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong,nonatomic) UILabel *message;@property (strong, nonatomic) UIWindow *window;@end
#import "AppDelegate.h"@implementation AppDelegate//*************************ios版本是6.1*************************- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ //设置应用的窗口大小,uiscreen()获取主屏幕的大小 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor grayColor]; //UIViewController *rootViewControler = [[UIViewController alloc]init]; //生成一个标签,通过frame的方式的设置坐标和大小 self.message = [[UILabel alloc]initWithFrame:CGRectMake(70, 200, 200, 20)]; //设置uilabel的字体对齐方式,在ios6中使用NSTextAlignment,UITextAlignment不被支持 //这是UITextAlignment的定义 /************************************************* enum { UITextAlignmentLeft = 0, UITextAlignmentCenter, UITextAlignmentRight, } NS_DEPRECATED_IOS(2_0,6_0); typedef NSTextAlignment UITextAlignment; *************************************************/ //这是NSTextAlignment的定义 /************************************************** enum { NSTextAlignmentLeft = 0, NSTextAlignmentCenter = 1, NSTextAlignmentRight = 2, NSTextAlignmentJustified = 3, NSTextAlignmentNatural = 4, }; typedef NSInteger NSTextAlignment; *************************************************/ //message.textAlignment = 1等价于 = NSTextAlignmentCenter;并且3,4是不可用的 self.message.textAlignment = 1; //设置标签上面的文本 self.message.text = @"Hello World!"; //设置标签上面的文本颜色 self.message.textColor = [UIColor blueColor]; //设置标签字体大小 self.message.font = [UIFont systemFontOfSize:23]; //将标签添加为window的子view [self.window addSubview:self.message]; //设置自定义的一个按钮,type设置为圆角矩形 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect ]; button.frame = CGRectMake(130, 250, 90 , 40); button.backgroundColor = [UIColor blackColor]; [button setTitle:@"Hello" forState:UIControlStateNormal]; [button setTitle:@"Hi,Go" forState:UIControlStateHighlighted]; //设置button的不同状态的图片样式 UIImage *normalImage = [UIImage imageNamed:@"屏幕快照 2013-05-26 上午10.45.15.png"]; UIImage *pressImage = [UIImage imageNamed:@"屏幕快照 2013-05-26 上午10.44.30.png"]; /* UIControlState,<< 这种位操作符表示这几个选项可以叠加 typedef NS_OPTIONS(NSUInteger, UIControlState) { UIControlStateNormal = 0, UIControlStateHighlighted = 1 << 0, // used when UIControl isHighlighted is set UIControlStateDisabled = 1 << 1, UIControlStateSelected = 1 << 2, // flag usable by app (see below) UIControlStateApplication = 0x00FF0000, // additional flags available for application use UIControlStateReserved = 0xFF000000 // flags reserved for internal framework use }; */ [button setBackgroundImage:normalImage forState:UIControlStateNormal]; [button setBackgroundImage:pressImage forState:UIControlStateHighlighted]; //给button添加事件和操作方法,@selector()通过hash映射的方式将方法转换,方便系统查找,提高效率 [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:button]; //button.currentTitle = @"Hello"; //测试NSDate NSDate *date = [NSDate date]; NSLog(@"[NSDate date] is %@",date); NSDate *userDate = [[NSDate alloc]init]; NSLog(@"[NSDate userDate] is %@",userDate); [date earlierDate:userDate]; NSLog(@"self.window.subviews : %@",self.window.subviews); [self.window makeKeyAndVisible]; return YES;; }#pragma mark buttonClickEvent- (void) click{ //静态局部变量做为控制开关 static BOOL flag; if (flag == 0) { self.message.text = @"Hello Xcode!"; flag =!flag; } else { self.message.text = @"Hello World!"; flag =!flag; } }
这里可以看到self.window.subviews的输出结果,有我们的label和button。
2013-05-26 12:41:10.233 emptyProject[10376:11303] self.window.subviews : (
"<UILabel: 0x76791b0; frame = (70 200; 200 20); text = 'Hello World!'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x7679290>>",
"<UIRoundedRectButton: 0x767b5d0; frame = (130 250; 90 40); opaque = NO; layer = <CALayer: 0x767b740>>"
- iOS中UILabel和UIButton的自定义设置
- iOS 使用storyboard设置UIButton 和UILabel 的圆角
- UIButton和UILabel的常见设置方法
- iOS设置改变UILabel、UIButton的多种颜色和字体大小(非常好用)
- Ios中导航栏和标签栏的结合以及UIButton、UILabel的使用
- UILabel和UIButton的属性
- UIButton和UILabel设置圆角
- UIButton和的UILabel添加下划线,中划线
- 设置UIButton中的文字和图片,设置UILabel的文在显示不同颜色
- UILabel 和UIButton的简单实用
- UIButton和UILabel的宽与高
- 【UILabel和UIButton】
- IOS中UIButton和UIImageView的区别
- 【学习中的分享】 iOS利用UILabel和UIButton制作一个简单的计算器
- iOS自定义UIButton的实现
- iOS中关于设置UIButton文字和图标对齐格式的问题
- 自定义UILabel设置行距和字间距的各种方法
- iOS-UI-02 UILabel UIButton
- 用三层结构实现添加学生
- 项目管理 : 高效经理的五个常用工具 (引用)
- struts2之单个文件上传
- 第四届全国蓝桥杯软件设计大赛 java软件开发本科B组 题目及答案
- jQuery插件编写
- iOS中UILabel和UIButton的自定义设置
- 20几岁男人应该懂得50件事
- Oracle 11g 客户端配置
- Linux之RHEL6的开机流程分析
- fedora18频繁死机,尝试解解决
- 输入服务子系统实例分析(韦东山的视频总结及针对linux-2.6.30.4)
- unix 与 linux 操作系统 介绍
- 各种排序方法
- 关于linux 僵尸进程