UIView 和其子类 UILabel 的基本方法

本文介绍了UIKit中UIView与UILabel的基本使用方法,包括初始化、设置属性、添加到视图层级等步骤,并展示了如何设置背景颜色、文本内容及样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIView

//    1.初始化一个 UIView 对象
//  UIView *view = [UIView alloc] 初始化方法];
//    2.设置UIView的属性 例如:颜色;
//    3.UIView(视图) 加载到窗口上;
//    4.释放对象
UIView *aView = [[UIView alloc] initWithFrame: initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
aView.backgroundColor = [UIColor redColor];
[superView addSubview:aView];
[aView release];
//设置背景颜色
如果没有给UIView设置背景颜色,默认的颜色是透明的;
View.backgroundColor = [UIColor yellowColor]
//将坐标变为字符串
NSStringFromCGPoint(<#CGPoint point#>)
//利用tag 取出视图
view2.tag = 1000 ; //必须提前给视图加上tag(别名);
UIView *tagView = [view viewWithTag:1000];

//把父视图上的某个子视图
    [view
insertSubview:view3 atIndex:0];//移动到指定位置
    [view
insertSubview:view3 atIndex:1];
    [view
insertSubview:view2 aboveSubview:view3];//移动到...上方
    [view
insertSubview:view2 belowSubview:view3];//移动到...下方

//bounds,   默认的起始点是0,0 ,高与frame相同;
   
//改变父视图的bounds
 
/*
    1.
子视图的坐标系
    2.
父视图没有变化
    3.
换来的坐标系(0,0)点改变,例如(10,10)即改变bounds
    4.
寻找现在的(0,0)(原点)
    5.
子视图根据新的坐标原点发生变化
   */
    //如果该视图被隐藏,其子视图也全部被隐藏.
    //view2.hidden = YES;
   
//设置透明度, alpha 范围 0 - 1 ;
   
//1是不透明,依次递减;
   
//view3.alpha = 0.5;
   
//view2.alpha = 0.5;
    //view.alpha = 0.5;

UILabel

//创建一个UILabel;
   
/*
     1.
初始化
     2.
设置属性
     3.
添加显示
     4.
释放对象
    */

   
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 500, 500)];
//    label.backgroundColor = [UIColor blackColor];
//    label.text = @"Application windows are expected to have a root view controller at the end of application launch”; //设置文本消息
//    label.textColor = [UIColor yellowColor];//文本颜色
//    label.textAlignment = NSTextAlignmentCenter;//对齐方式
//   
//    //如果想有多少显示多少就给0
//    label.numberOfLines = 0;
//    label.shadowColor = [UIColor redColor];
//    label.shadowOffset = CGSizeMake(-3, -3);
//    label.font = [UIFont systemFontOfSize:20];
//    //打印已安装的字体
////    NSArray *fontArray =[UIFont familyNames];
////    for (NSString *name in fontArray) {
////        NSLog(@"%@",name);
////    }
//    //设置字体
//   label.font = [UIFont fontWithName:@"Zapfino" size:30];
////   
//    //设置断行
//    //label.lineBreakMode = NSLineBreakByTruncatingHead;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值