Objective-C语言——UILabel标签

 Objective-C语言——UILabel标签


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //获取屏幕的尺寸
//    UIScreen *screen = [UIScreen mainScreen];
//    CGFloat width = screen.bounds.size.width; //宽
//    CGFloat height = screen.bounds.size.height; //高
或
//    CGFloat width = [UIScreen mainScreen].bounds.size.width; // 宽
//    CGFloat height = [UIScreen mainScreen].bounds.size.height; //高
    
    
    //UILabel
    //初始化
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
//    UILabel *label = [[UILabel alloc] init];
    
    
   
    label.frame = CGRectMake(ScreenWidth/2-150, ScreenHeight/2-150, 300, 300);
    
    //文本内容
    label.text = @"Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a ";
    
    //字体大小
    label.font = [UIFont systemFontOfSize:30];
    
    
    //找出所有的字体样式
    NSArray *familyNamesArray = [UIFont familyNames];
    NSLog(@"%@",familyNamesArray);
    
    
    for (NSString *a in [UIFont familyNames]) {
        NSLog(@"%@",a);
    
    }
    
    //只对英文和数字有效
    label.font = [UIFont fontWithName:@"Bodoni 72 Oldstyle" size:32];
    
    //加粗
    label.font = [UIFont boldSystemFontOfSize:20];
    
    //文本颜色
    label.textColor = [UIColor yellowColor];
    
    //在 label 中使文本换行
    label.numberOfLines = 0; //0代表不限制label 的行数
    
    //文本对齐方式,默认是NSTextAlignmentLeft,   textAlignment是枚举
//    label.textAlignment = NSTextAlignmentCenter; // label.textAlignment = 1;
    
    //设置文本过长时的显示格式
//    label.lineBreakMode = NSLineBreakByTruncatingMiddle;//  "ab...yz"
    
    //label 背景颜色
    label.backgroundColor = [UIColor purpleColor];
    
    //view 背景颜色
    self.view.backgroundColor = [UIColor yellowColor];
    
    //Label文字大小自适应
    [label sizeToFit];

    

//    //边框
//    label.layer.borderColor = [[UIColor magentaColor] CGColor];
//    label.layer.borderWidth = 5;
//
    
label.enabled = NO;    
    
    //显示在 view
    [self.view addSubview:label];
    
    
    
    
    //初始化
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectZero];
    
    NSString *string = @"Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.";
    label1.text = string;
    
    label1.frame = CGRectMake(ScreenWidth/2-150, ScreenHeight/2-150, 300, 300);
    
    label1.backgroundColor = [UIColor blueColor];
    
    label1.font = [UIFont systemFontOfSize:18];
    
    CGSize size = [string sizeWithAttributes:@{NSFontAttributeName:label1.font}];
    
    label1.frame = CGRectMake(ScreenWidth/2 - size.width/2, ScreenHeight/2 - size.height/2, size.width, size.height);
    
//    [self.view addSubview:label1];
   
    
    
    
    
    
}

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

@end



运行结果

2016-01-06 08:57:33.589 UI_01_01[568:7164] (

    Copperplate,

    "Heiti SC",

    "Iowan Old Style",

    "Kohinoor Telugu",

    Thonburi,

    "Heiti TC",

    "Courier New",

    "Gill Sans",

    "Apple SD Gothic Neo",

    "Marker Felt",

    "Avenir Next Condensed",

    "Tamil Sangam MN",

    "Helvetica Neue",

    "Gurmukhi MN",

    "Times New Roman",

    Georgia,

    "Apple Color Emoji",

    "Arial Rounded MT Bold",

    Kailasa,

    "Kohinoor Devanagari",

    "Kohinoor Bangla",

    "Chalkboard SE",

    "Sinhala Sangam MN",

    "PingFang TC",

    "Gujarati Sangam MN",

    Damascus,

    Noteworthy,

    "Geeza Pro",

    Avenir,

    "Academy Engraved LET",

    Mishafi,

    Futura,

    Farah,

    "Kannada Sangam MN",

    "Arial Hebrew",

    Arial,

    "Party LET",

    Chalkduster,

    "Hoefler Text",

    Optima,

    Palatino,

    "Lao Sangam MN",

    "Malayalam Sangam MN",

    "Al Nile",

    "Bradley Hand",

    "PingFang HK",

    "Trebuchet MS",

    Helvetica,

    Courier,

    Cochin,

    "Hiragino Mincho ProN",

    "Devanagari Sangam MN",

    "Oriya Sangam MN",

    "Snell Roundhand",

    "Zapf Dingbats",

    "Bodoni 72",

    Verdana,

    "American Typewriter",

    "Avenir Next",

    Baskerville,

    "Khmer Sangam MN",

    Didot,

    "Savoye LET",

    "Bodoni Ornaments",

    Symbol,

    Menlo,

    "Bodoni 72 Smallcaps",

    Papyrus,

    "Hiragino Sans",

    "PingFang SC",

    "Euphemia UCAS",

    "Telugu Sangam MN",

    "Bangla Sangam MN",

    Zapfino,

    "Bodoni 72 Oldstyle"

)

2016-01-06 08:57:33.590 UI_01_01[568:7164] Copperplate

2016-01-06 08:57:33.590 UI_01_01[568:7164] Heiti SC

2016-01-06 08:57:33.590 UI_01_01[568:7164] Iowan Old Style

2016-01-06 08:57:33.591 UI_01_01[568:7164] Kohinoor Telugu

2016-01-06 08:57:33.591 UI_01_01[568:7164] Thonburi

2016-01-06 08:57:33.591 UI_01_01[568:7164] Heiti TC

2016-01-06 08:57:33.591 UI_01_01[568:7164] Courier New

2016-01-06 08:57:33.591 UI_01_01[568:7164] Gill Sans

2016-01-06 08:57:33.592 UI_01_01[568:7164] Apple SD Gothic Neo

2016-01-06 08:57:33.592 UI_01_01[568:7164] Marker Felt

2016-01-06 08:57:33.592 UI_01_01[568:7164] Avenir Next Condensed

2016-01-06 08:57:33.592 UI_01_01[568:7164] Tamil Sangam MN

2016-01-06 08:57:33.592 UI_01_01[568:7164] Helvetica Neue

2016-01-06 08:57:33.592 UI_01_01[568:7164] Gurmukhi MN

2016-01-06 08:57:33.593 UI_01_01[568:7164] Times New Roman

2016-01-06 08:57:33.593 UI_01_01[568:7164] Georgia

2016-01-06 08:57:33.593 UI_01_01[568:7164] Apple Color Emoji

2016-01-06 08:57:33.593 UI_01_01[568:7164] Arial Rounded MT Bold

2016-01-06 08:57:33.593 UI_01_01[568:7164] Kailasa

2016-01-06 08:57:33.593 UI_01_01[568:7164] Kohinoor Devanagari

2016-01-06 08:57:33.594 UI_01_01[568:7164] Kohinoor Bangla

2016-01-06 08:57:33.594 UI_01_01[568:7164] Chalkboard SE

2016-01-06 08:57:33.594 UI_01_01[568:7164] Sinhala Sangam MN

2016-01-06 08:57:33.594 UI_01_01[568:7164] PingFang TC

2016-01-06 08:57:33.594 UI_01_01[568:7164] Gujarati Sangam MN

2016-01-06 08:57:33.595 UI_01_01[568:7164] Damascus

2016-01-06 08:57:33.595 UI_01_01[568:7164] Noteworthy

2016-01-06 08:57:33.595 UI_01_01[568:7164] Geeza Pro

2016-01-06 08:57:33.595 UI_01_01[568:7164] Avenir

2016-01-06 08:57:33.595 UI_01_01[568:7164] Academy Engraved LET

2016-01-06 08:57:33.595 UI_01_01[568:7164] Mishafi

2016-01-06 08:57:33.596 UI_01_01[568:7164] Futura

2016-01-06 08:57:33.596 UI_01_01[568:7164] Farah

2016-01-06 08:57:33.596 UI_01_01[568:7164] Kannada Sangam MN

2016-01-06 08:57:33.596 UI_01_01[568:7164] Arial Hebrew

2016-01-06 08:57:33.596 UI_01_01[568:7164] Arial

2016-01-06 08:57:33.596 UI_01_01[568:7164] Party LET

2016-01-06 08:57:33.597 UI_01_01[568:7164] Chalkduster

2016-01-06 08:57:33.597 UI_01_01[568:7164] Hoefler Text

2016-01-06 08:57:33.597 UI_01_01[568:7164] Optima

2016-01-06 08:57:33.597 UI_01_01[568:7164] Palatino

2016-01-06 08:57:33.597 UI_01_01[568:7164] Lao Sangam MN

2016-01-06 08:57:33.597 UI_01_01[568:7164] Malayalam Sangam MN

2016-01-06 08:57:33.597 UI_01_01[568:7164] Al Nile

2016-01-06 08:57:33.598 UI_01_01[568:7164] Bradley Hand

2016-01-06 08:57:33.598 UI_01_01[568:7164] PingFang HK

2016-01-06 08:57:33.598 UI_01_01[568:7164] Trebuchet MS

2016-01-06 08:57:33.598 UI_01_01[568:7164] Helvetica

2016-01-06 08:57:33.598 UI_01_01[568:7164] Courier

2016-01-06 08:57:33.599 UI_01_01[568:7164] Cochin

2016-01-06 08:57:33.599 UI_01_01[568:7164] Hiragino Mincho ProN

2016-01-06 08:57:33.599 UI_01_01[568:7164] Devanagari Sangam MN

2016-01-06 08:57:33.599 UI_01_01[568:7164] Oriya Sangam MN

2016-01-06 08:57:33.599 UI_01_01[568:7164] Snell Roundhand

2016-01-06 08:57:33.599 UI_01_01[568:7164] Zapf Dingbats

2016-01-06 08:57:33.600 UI_01_01[568:7164] Bodoni 72

2016-01-06 08:57:33.600 UI_01_01[568:7164] Verdana

2016-01-06 08:57:33.600 UI_01_01[568:7164] American Typewriter

2016-01-06 08:57:33.600 UI_01_01[568:7164] Avenir Next

2016-01-06 08:57:33.600 UI_01_01[568:7164] Baskerville

2016-01-06 08:57:33.600 UI_01_01[568:7164] Khmer Sangam MN

2016-01-06 08:57:33.601 UI_01_01[568:7164] Didot

2016-01-06 08:57:33.601 UI_01_01[568:7164] Savoye LET

2016-01-06 08:57:33.601 UI_01_01[568:7164] Bodoni Ornaments

2016-01-06 08:57:33.601 UI_01_01[568:7164] Symbol

2016-01-06 08:57:33.601 UI_01_01[568:7164] Menlo

2016-01-06 08:57:33.601 UI_01_01[568:7164] Bodoni 72 Smallcaps

2016-01-06 08:57:33.602 UI_01_01[568:7164] Papyrus

2016-01-06 08:57:33.602 UI_01_01[568:7164] Hiragino Sans

2016-01-06 08:57:33.602 UI_01_01[568:7164] PingFang SC

2016-01-06 08:57:33.602 UI_01_01[568:7164] Euphemia UCAS

2016-01-06 08:57:33.602 UI_01_01[568:7164] Telugu Sangam MN

2016-01-06 08:57:33.602 UI_01_01[568:7164] Bangla Sangam MN

2016-01-06 08:57:33.603 UI_01_01[568:7164] Zapfino

2016-01-06 08:57:33.603 UI_01_01[568:7164] Bodoni 72 Oldstyle



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是用Objective-C纯代码实现的签到日期界面。实现的界面包括一个导航栏、一个显示当前日期的标签和一个签到按钮。 ViewController.h文件: ```objective-c #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end ``` ViewController.m文件: ```objective-c #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UILabel *dateLabel; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // 设置导航栏标题 self.navigationItem.title = @"签到"; // 设置背景颜色 self.view.backgroundColor = [UIColor whiteColor]; // 创建并添加日期标签 self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)]; self.dateLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2 - 50); self.dateLabel.textAlignment = NSTextAlignmentCenter; self.dateLabel.textColor = [UIColor blackColor]; [self.view addSubview:self.dateLabel]; // 更新日期标签的文本 [self updateDateLabel]; // 创建并添加签到按钮 UIButton *checkInButton = [UIButton buttonWithType:UIButtonTypeSystem]; checkInButton.frame = CGRectMake(0, 0, 200, 50); checkInButton.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2 + 50); [checkInButton setTitle:@"签到" forState:UIControlStateNormal]; [checkInButton addTarget:self action:@selector(checkInButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:checkInButton]; } // 更新日期标签的文本 - (void)updateDateLabel { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy年MM月dd日"; self.dateLabel.text = [formatter stringFromDate:[NSDate date]]; } // 签到按钮点击事件 - (void)checkInButtonClicked:(UIButton *)sender { // TODO: 处理签到逻辑 // 更新日期标签的文本 [self updateDateLabel]; } @end ``` 在AppDelegate.m文件中,将ViewController设置为根视图控制器: ```objective-c #import "AppDelegate.h" #import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; ViewController *viewController = [[ViewController alloc] init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; self.window.rootViewController = navigationController; [self.window makeKeyAndVisible]; return YES; } ``` 这样就完成了一个简单的签到日期界面的实现。运行程序后,可以看到一个带有日期标签和签到按钮的界面。点击签到按钮后,日期标签上的日期会更新为当前日期。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值