iOS編程------UILabel

//
//  AppDelegate.h
//  UI01_UILabel
//
//  Created by tanlon on 15/8/31.
//  Copyright (c) 2015年 . All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end


//
//  AppDelegate.m
//  UI01_UILabel
//
//  Created by tanlon on 15/8/31.
//  Copyright (c) 2015年 . All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
- (void)dealloc{
    [_window release];
    [super dealloc];
}

- (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 主要用來展示一小段文字,起到說明作用,大段文字不使用UILabel,使用UITextView
    //UILabel 的使用分爲創建,設置屬性,添加,釋放,四步.
    //UILabel屬於UIView的子類,我們在API中查看一個類的使用時,如果該類有自己的初始化方法,就使用自己的初始化方法,如果沒有,就使用父類的初始化方法.

    //1.創建UILabel
    UILabel *userNameLabel = [[UILabel alloc] initWithFrame:(CGRectMake(50, 50, 120, 50))];

    //2.設置屬性
    userNameLabel.text = @"用戶名 long long ago";                 //設置文本
    userNameLabel.textColor = [UIColor redColor];                //設置文本顏色
    userNameLabel.font = [UIFont systemFontOfSize:18];           //設置文本字體
    userNameLabel.lineBreakMode = NSLineBreakByCharWrapping;     //設置換行模式
    userNameLabel.numberOfLines = 0;                             //設置自動換行, 0 表示自動換行
    userNameLabel.shadowColor = [UIColor purpleColor];           //陰影顏色
    userNameLabel.shadowOffset = CGSizeMake(2, 2);               //陰影偏移量 CGSize類型

    //3.添加到父視圖上
    [self.window addSubview:userNameLabel];

    //4.釋放
    [userNameLabel release];


    return YES;
}

@end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章