您的位置:首页 > 产品设计 > UI/UE

UILabel、UITextField、UIButton简单使用

2014-09-02 08:24 316 查看
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

//UILabel的使用  作用;label所有的api都和文本的显示有关
UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 280, 150)];
//显示文字
lable.text = @"新浪播客新浪播客新浪播客新浪播客新浪播客新浪播客新浪播客μ≤μ√……∑′¨′…………";
//文本字体
lable.font = [UIFont systemFontOfSize:15];
//断行的形式
lable.lineBreakMode = NSLineBreakByTruncatingMiddle; //从中间断行
//文本的位置.局中
lable.textAlignment = NSTextAlignmentCenter;
//文本颜色
lable.textColor = [UIColor blackColor];
//文本阴影颜色
lable.shadowColor = [UIColor yellowColor];
//文本的阴影便宜量
lable.shadowOffset = CGSizeMake(2, 2);
//字体
//    lable.font = [UIFont fontWithName:@"Marlett" size:20];
//设置lable显示文字的行数  ,设置为0时候不限制行数
lable.numberOfLines = 0;
//在赋值之后,让lable自己适应文本高度
[lable sizeToFit];
lable.backgroundColor = [UIColor magentaColor];
[self.window addSubview:lable];
lable.alpha = 0.2;
[lable release];
//UITextField的使用 单行文本输入框

UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(20, 120, 280, 30)];
textfield.backgroundColor = [UIColor cyanColor];

//文本控制的api
//    textfield.text = @"请输入用户名";
textfield.placeholder = @"请输入用户名";   //占用字符串
textfield.textAlignment = NSTextAlignmentCenter;  //局中

//外观控制api
textfield.borderStyle = UITextBorderStyleRoundedRect;   //圆角
//    textfield.borderStyle = UITextBorderStyleLine;    //方角
//    textfield.borderStyle = UITextBorderStyleBezel;

//右侧清楚按钮的显示方式
textfield.clearButtonMode = UITextFieldViewModeAlways;

//设置输入框的左视图
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 100)];
view.backgroundColor = [UIColor redColor];
//设置一个view
textfield.leftView = view;
textfield.leftViewMode = UITextFieldViewModeAlways;
[view release];

//输入控制的api
textfield.secureTextEntry = YES; //输入的文字都是原点显示
//设置键盘样式
//    textfield.keyboardType = UIKeyboardTypeNumberPad;   //数字键盘
textfield.keyboardType = UIKeyboardTypePhonePad;
//设置键盘的值
textfield.tag = 10000;

[self.window addSubview:textfield];

[textfield release];
//UIButton 的使用

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
//给按钮家标题
[button setTitle:@"登录" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];   //标题颜色
[button setShowsTouchWhenHighlighted:YES];  //设置点击高亮颜色
button.frame = CGRectMake(20, 200, 100, 40);
button.backgroundColor = [UIColor redColor];
button.alpha = 0.5;

//给按钮绑定一个方法,当按钮被点击的时候调用   参数1.命令谁去调用方法   参数2.前面对象调用后面方法   参数3.按钮属于什么状态下触发这个方法
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

[self.window addSubview:button];

//让textField的键盘回收的方法
[_window release];
return YES;
}
//按钮的触发方法
- (void)buttonClicked:(UIButton *)button
{
//点击textField的键盘回收  ,1.获得textField的对象
//通过视图的tag值,找子视图
UITextField *textField = (UITextField *)[_window viewWithTag:10000];

//2.回收键盘
[textField resignFirstResponder];

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你正在进行违规操作!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertView show];
[alertView release];
_window.backgroundColor = [UIColor whiteColor];

NSLog(@"点击来一下下下下下");
}
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: