UI01_UILabel

来源:互联网 发布:久坐肚子大 知乎 编辑:程序博客网 时间:2024/06/05 16:45

 /**********************************************************************************/

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    

    self.window =[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

    self.window.backgroundColor =[UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    [_windowrelease];


    UIViewController *vc =[[UIViewControlleralloc]init];

    self.window.rootViewController =vc;

    [vc release];

    

    

    

//    UIView *view1 =[[UIView alloc] initWithFrame:CGRectMake(80, 80, 100, 100)];

//    view1.backgroundColor =[UIColor blackColor];

//    [self.window addSubview:view1];

//    [view1 release];

//    

//    UIView *view2 =[[UIView alloc] initWithFrame:CGRectMake(100, 150, 100, 100)];

//    view2.backgroundColor =[UIColor redColor];

//    [self.window addSubview:view2];

//    [view2 release];

    

    

    //////////////////UILabel

    UILabel *label1 =[[UILabelalloc] initWithFrame:CGRectMake(80,80, 100, 100)];

    label1.backgroundColor =[UIColoryellowColor];

    [self.windowaddSubview:label1];

    [label1 release];

    /// label添加文本

      label1.text =@"程锦乐,afadf,水电费是sf,阿斯顿发撒旦,dfgdfg,dfgdfg,dfgdfgd";

    ///设置文本的颜色

    label1.textColor =[UIColorgreenColor];

   /// 设置文本的对齐方式

    label1.textAlignment =NSTextAlignmentCenter;

   ///设置文本字体大小

    label1.font =[UIFontsystemFontOfSize:15];

    /// 设置行数

    label1.numberOfLines =0;

    [label1 sizeToFit];

   //想通过这两方法进行自适应的话,必须先有文本,后有对行数和sizeToFit的设置

   //它会自动修改尺寸,把高度增加

    NSLog(@"%g",label1.frame.size.height);

    // shadw  增加阴影

    label1.shadowColor = [UIColor redColor];

    // shadw  扩充阴影

    label1.shadowOffset =CGSizeMake(2,2);

   //center只能设置位置,而且还是中心点的位置

    //frame都可以进行设置

    label1.center =CGPointMake(0,0);

    label1.center =CGPointMake(100+label1.frame.size.width / 2 , 100+label1.frame.size.height /2);

    

    

    

    /// 随机颜色

    [UIColorcolorWithRed:arc4random()%256/255.0green:arc4random()%256/255.0blue:arc4random()%256/255.0alpha:1];

    

    

    

    return YES;

}



1 0
原创粉丝点击