步步入佳境---UI入门(4) --简单练习

一,创建SingleViewApplication

1,UILabel的简单使用

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 200)];
    label.text=@"labelada dsfsfsf sfsf sf sfs fsdfsafs sfsdfs  sdfsdf  sdfs df sdf sdf ";
    label.font=[UIFont fontWithName:@"chalkboard se" size:25];
    label.textColor=[UIColor orangeColor];
    label.lineBreakMode=NSLineBreakByCharWrapping;
    label.numberOfLines=3;//保留的行数
    label.highlighted=YES;//文字是否高亮显示
    label.highlightedTextColor=[UIColor greenColor];//文字高亮显示的颜色
    [label setTextAlignment:NSTextAlignmentCenter];//对齐方式
    [self.view addSubview:label];
    label.shadowColor=[UIColor blackColor];//设置阴影颜色
    label.shadowOffset=CGSizeMake(2, 5);
    label.userInteractionEnabled=NO;//是否可以与用户交互
    label.backgroundColor=[UIColor redColor];

2,UITextField的简单使用

 UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];
    textField.borderStyle=UITextBorderStyleRoundedRect;//框的样式
    [textField setText:@"李长鸿"];                         //text值
    [textField setTextAlignment:NSTextAlignmentCenter];  //对齐方式
    textField.textColor =[UIColor redColor];            //text颜色
    [self.view addSubview:textField];

3,UIButton的简单使用

 UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(100, 100, 80, 60)];//初始化按钮和边框大小
    [button setBackgroundColor:[UIColor whiteColor]];        //设置按钮背景色
    [button setTitle:@"李长鸿" forState:UIControlStateNormal];//设置按钮文字
    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];//设置按钮文字颜色
    button.titleLabel.shadowColor=[UIColor redColor];//设置字体阴影
    button.titleLabel.shadowOffset=CGSizeMake(2, 5);//阴影偏移
    button.titleLabel.font=[UIFont fontWithName:@"chalkboard se" size:25];//设置字体和大小
    [self.view addSubview:button];

4,UIActionSheet的简单使用

首先这个类要实现<UIActionSheetDelegate>协议,写法:@interface ViewController : UIViewController<UIActionSheetDelegate>
//UIAlertView只有一个选择项,相当于windows里的messagebox,UIActionsheet至少有两个选项
    //创建ActionSheet需要多个参数
    //(1)initWithTitle:设置标题,将会显示在ActionSheet的顶部
    //(2)delegate:shezhiActionSheet的一个按钮被按下后,它的delegate会被通知,执行这个delegate的actionSheet:didDismissWithButtonIndex方法将会执行,这里设为self,就可保证我们自己在ViewController.m中写的这个方法被执行.
    //(3)cancelButtonTitle:设置取消按钮标题,这个按钮会显示在ActionSheet的最下边
    //(4)destructiveButtonTitle:设置第一个确定按钮的标题
    //(5)otherButtonTitle:可以设置多个确定按钮,想要添加两个按钮,可以写成
    //otherbuttonTitles:@"New Button1",@"New Button2",nil     
}
-(void)onClick:(UIButton *)button
{
    UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:@"Do You Love Me?" delegate:self cancelButtonTitle:@"不选择" destructiveButtonTitle:@"Yes,i love you" otherButtonTitles:@"guess", nil];   
    [actionSheet showInView:self.view];  
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //添加点击事件的方法...
}

5,UISlertView的简单使用    //创建一个alert也要许多参数
    //1,initWithTitle:设置标题,将会显示在Alert的顶部
    //2,message:设置提示消息内容
    //3,delegate:设置Alert的委托,这里,我们设置为self
    //4,cancelButtonTitle:设置取消按钮的标题
    //5,otherButtonTitles:与ActionSheet类似
    //[alert show]用于显示
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"通知" message:@"你来晚了" delegate:self cancelButtonTitle:@"来了"       otherButtonTitles:@"我来晚咋啦", nil];
    [alertView show];

 6,窗口UIWindow
    UIWindow有一个比较重要的属性rootViewController,用于装载窗口里面第一个视图.这个属性是UIViewController类型的
    UIWindow有一个比较重要的方法makeKeyAndVisible,这个方法的作用是设置当前window为主window,并且将其内容显示出来

原文地址:https://www.cnblogs.com/huntaiji/p/3428205.html