IOS開發之UILabel



#import "AppDelegate.h"app


@interface AppDelegate ()ide


@end 字體


@implementation AppDelegateui



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

    // Override point for customization after application launch.spa


    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];.net

    

    [_window setBackgroundColor:[UIColor cyanColor]];3d

    

#pragma mark UILabel的建立rest

    //====================UILabel的建立=====================orm

    //UILabel:UIView UIView屬性和方法UILabel都擁有

    //做用是專門用來顯示文字的控件

    //1.建立一個UILabel對象

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake

                        (50, 50, 250, 600)];

    

    //2.設置背景顏色

    label.backgroundColor = [UIColor yellowColor];

                      

    //3.顯示在界面上

    [_window addSubview:label];

    

#pragma mark label相關屬性

    //==================label相關屬性=======================

    //4.設置文本內容text

    [label setText:@"Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHanHello LuHan !!"];

    

    //5.設置字體

    //UIFontUI字體類;建立系統字體而且設置字體大小;

    [label setFont:[UIFont systemFontOfSize:20]];

   

    //系統默認加粗字體;

   // UIFont *font1 = [UIFont boldSystemFontOfSize:15];

    

    //系統默認斜體

    UIFont *font2 = [UIFont italicSystemFontOfSize:30];

    

    //拿到當前系統支持的全部的字體名

    NSArray *allFontName = [UIFont familyNames];

    // NSLog(@"%@",allFontName);

    //設置字體名和字體大小;

    UIFont *font3 = [UIFont fontWithName:@"Zapfino" size:20];

    

    //ttf字體庫的文件後綴(自學內容)

    [label setFont:font3];


    //6.設置文字顏色(默認黑色)

    label.textColor = [UIColor redColor];

    

    //7.設置陰影顏色

    label.shadowColor = [UIColor blackColor];

    

    //8.設置陰影偏移

    [label setShadowOffset:CGSizeMake(-2, -2)];

  

    //9.設置字體的對齊模式

    //NSTextAlignmentLeft(默認是居左的);

    //NSTextAlignmentCenter

    //NSTextAlignmentRight

    [label setTextAlignment:NSTextAlignmentLeft];

    

    //10.設置換行模式

//    NSLineBreakByWordWrapping = 0,  //以單詞爲單位換行,顯示不了的內容以

    //單詞截斷,後面的直接不顯示;

//    NSLineBreakByCharWrapping, /* Wrap at character boundaries */

//    NSLineBreakByClipping,//仍是以單詞換行,

    //最後顯示不全的部分在label後面直接截斷,後面直接不顯示

//    NSLineBreakByTruncatingHead,//顯示不全,最後一行將最後的內容顯示前面使用...代替;

//    NSLineBreakByTruncatingTail, /* Truncate at tail of line: "abcd..." */

//    NSLineBreakByTruncatingMiddle /* Truncate middle of line:  "ab...yz" */


    [label setLineBreakMode:NSLineBreakByWordWrapping];

    

    //11.設置顯示的行數;(要適應label的高度!!)

    [label setNumberOfLines:3];

    

    //12.自動換行

    //a.設置行數爲0

    [label setNumberOfLines:0];

    //b.設置自動換行模式

    [label setLineBreakMode:NSLineBreakByWordWrapping];

    

    //13.自適應寬度(將字體縮放,讓全部的文字都顯示出來);

    [label setAdjustsFontSizeToFitWidth:YES];

    

    

    

    

    [_window makeKeyAndVisible];

    

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end

相關文章
相關標籤/搜索