UI第一天

来源:互联网 发布:用户运营数据挖掘 编辑:程序博客网 时间:2024/06/06 04:31
1.UIView和所有继承自UIView的子类的对象创建的过程
/*
     1.初始化UIView的对象UIView *MyView = [[UIView alloc] 初始化方法];
     2.
设置属性,颜色尺寸等
     3.
把视图加载到窗口上
     4.
释放对象
     */

   
    //子视图的起始点是指的是其[父视图的起始点]开始计算
    UIView *aview = [[UIView alloc] initWithFrame:CGRectMake(50,50,200,50)];//x,y,宽,高
    aview.backgroundColor = [UIColor blackColor];
    [self.window addSubview:aview];//把视图加载到窗口上,那么window就是view的父视图
    [aview release];
//============================
2.UIView 的frame,center,bounds属性
(1).frame 是CGRect类型,有x,y,宽,高
struct CGRect {
  CGPoint origin;
  CGSize size;
};
typedef structCGRect CGRect;
//origin起始点
struct CGPoint {
  CGFloat x;
  CGFloat y;
};
typedef structCGPoint CGPoint;
//尺寸大小
struct CGSize {
  CGFloat width;
  CGFloat height;
};
(2).center代表中心点
center.x = frame.origin.x + frame.size.width/2;
center.y = frame.origin.y + frame.size.height/2;
(3).bounds属性
 /*bounds 默认的起始点是(0,0)宽高和frame的相同,修改父视图的bounds就是
     1
修改了子视图的坐标系,
     2.
父视图没有变化,
     3.
原来的坐标系的(0,0)点变化,如改成了(10,10),即改变bounds
     4.
寻找现在的(0,0),子视图根据新的坐标原点发生变化
     */
aview.bounds = CGRectMake(10, 10, 100, 100);//这里aview是其他两个子类view的属性
子类视图将会向左向上分别移动10个单位
2.常用属性
//NSStringFrom...把不同类型的数据转成NSString
  NSLog(@"%@",NSStringFromCGPoint(aview.center ));
//hidden视图隐藏,如果该视图被隐藏其子视图也被隐藏
  aview.hidden = YES;
//alpha透明度,设置视图的透明度0-1之间,1是不透明,依次递减,子视图的透明度随其父视图的透明度而改变
    aview.alpha = 0.8;
    //superview 获取父视图
    [dview superview].backgroundColor = [UIColorbrownColor];
    //subviews 获取所有子视图
    NSArray *arr = [aviewsubviews];
    //提前给视图添加一个标签
    aview.tag = 100;
    //利用tag值取出子视图(必须是标记视图的父视图调用viewWithTag方法)
    [self.windowviewWithTag:100].backgroundColor = [UIColorblackColor];
3.UILabel
 
UILabel *aLable = [[UILabelalloc] initWithFrame:CGRectMake(50,50, 100, 100)];
    aLable.text = @"Application windows are expected to have a root view controller at the end of application launch";
    //文字,背景颜色
    aLable.textColor = [UIColorredColor];
    aLable.backgroundColor = [UIColorbrownColor];
    aLable.textAlignment = NSTextAlignmentCenter;
    //显示行数
    aLable.numberOfLines = 0;
    //阴影的位
    aLable.shadowColor = [UIColorblackColor];
    aLable.shadowOffset = CGSizeMake(2, 1);
    //改变字体属性
   //打印出已安装的所有字体
    NSArray *arr = [UIFontfamilyNames];
    for (id objin arr) {
        NSLog(@"%@",obj);
    } 
    aLable.font = [UIFontfontWithName:@" Zapfino"size:20];
    //修改字体的大写
    aLable.font = [UIFontsystemFontOfSize:24];
    //断行lineBreakMode
    aLable.lineBreakMode = NSLineBreakByTruncatingMiddle;//以单词为单位换
    //断行形式
    typedef NS_ENUM(NSInteger, NSLineBreakMode) {        /* What to do with long lines */
        NSLineBreakByWordWrapping = 0,         /* Wrap at word boundaries, default */
        NSLineBreakByCharWrapping,       /* Wrap at character boundaries */
        NSLineBreakByClipping,      /* Simply clip */
        NSLineBreakByTruncatingHead,     /* Truncate at head of line: "...wxyz" */
        NSLineBreakByTruncatingTail,     /* Truncate at tail of line: "abcd..." */
        NSLineBreakByTruncatingMiddle    /* Truncate middle of line:  "ab...yz" */
    } NS_ENUM_AVAILABLE_IOS(6_0);
   
    [self.windowaddSubview:aLable];
    [aLable release];
 

(4).拓展(明天补充)
UITextField *loginText = [[UITextFieldalloc] initWithFrame:CGRectMake(140,100, 150, 25)];
     [self.windowaddSubview:loginText];
    loginText.borderStyle = UITextBorderStyleRoundedRect;//边框类型
    loginText.placeholder = @"请输入密码";//默认显示的文字
    loginText.clearButtonMode = UITextFieldViewModeWhileEditing;//编辑的删除按钮


 UIButton * btn = [[UIButtonalloc] initWithFrame:CGRectMake(50,400, 50, 25)];
    [btn setTitle: @"注册"forState: UIControlStateNormal];//设置默认状态下的文字
    [btn setTitleColor:[UIColorblueColor] forState:UIControlStateNormal];//设置默认状态下的颜色
    btn.titleLabel.font = [UIFontsystemFontOfSize: 14.0];
    [self.windowaddSubview: btn];
0 0
原创粉丝点击