你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS界面開發之UILabel

IOS界面開發之UILabel

編輯:IOS開發綜合

這裡記載了UILabel的一些罕見操作,和封閉以後界面的代碼。

//
//  LabelViewController.m
//  UIViewDemo
//
//  Created by dcr on 2016/12/16.
//  Copyright © 2016年 All rights reserved.
//

#import "LabelViewController.h"

@interface LabelViewController ()

@end

@implementation LabelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];
    CGRect rect = [[UIApplication sharedApplication] statusBarFrame];
    UIButton *btnImageView = [UIButton buttonWithType:UIButtonTypeSystem];
    btnImageView.frame = CGRectMake(0, rect.size.height, 100, 40);
    btnImageView.backgroundColor = [UIColor whiteColor];
    btnImageView.titleLabel.font = [UIFont systemFontOfSize:16];
    [btnImageView setTitle:@"前往" forState:UIControlStateNormal];
    [btnImageView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnImageView addTarget:self action:@selector(btnBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnImageView];
    
    //文本標簽
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(10, 100, 250, 200);
    label.backgroundColor = [UIColor yellowColor];
    //設置文本
    label.text = @"學習IOS記載,Foundation框架學習,由於Swift言語不斷有在更新,且IOS開發中有很多庫都是運用Objective-C言語的,所以Objective-C的學習還是很有必要的,上面是對NSString學習的一些記載。Foundation框架學習之NSArray和NSMutableArray";
    //文字規劃形式
    label.textAlignment = NSTextAlignmentCenter;
    //文字顏色,可自定義顏色值
    label.textColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];
    //label這通明
    //label.alpha = 0.5;
    //設置字體
    //label.font = [UIFont systemFontOfSize:20];
    //加粗
    //label.font = [UIFont boldSystemFontOfSize:20];
    //傾斜,只對英文無效
    label.font = [UIFont italicSystemFontOfSize:20];
    //遍歷一切字體
    for(NSString *name in [UIFont familyNames]){
        NSLog(@"font family name = %@", name);
    }
    //設置零碎支持的恣意字體
    label.font = [UIFont fontWithName:@"Times New Roman" size:25];
    //設置暗影
    //label.shadowColor = [UIColor redColor];
    //label.shadowOffset = CGSizeMake(2, 2);
    
    //換行自順應大小
    //換行形式 普通選擇字符換行,還有單詞NSLineBreakByWordWrapping
    label.lineBreakMode = NSLineBreakByCharWrapping;
    //顯示行數  0或許-1表示不限制行數
    label.numberOfLines = 0;
    
    //依據字符串的大小計算Label的大小
    CGSize size = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(250, 10000) lineBreakMode:NSLineBreakByWordWrapping];
    //依據字符區域大小重新設置label的大小
    label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, size.width, size.height);
    [self.view addSubview:label];
}

- (void)btnBack{
    //封閉以後窗口
    [self dismissViewControllerAnimated:true completion:^{
        NSLog(@"LabelViewController back completion");
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


【IOS界面開發之UILabel】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved