zoukankan      html  css  js  c++  java
  • UILabel

    #import "AppDelegate.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate

    - (void)dealloc

    {

        self.window = nil;

        [super dealloc];

    }

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

        self.window = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];

        self.window.backgroundColor = [UIColor whiteColor];

        [self.window makeKeyAndVisible];

        

        self.window.rootViewController = [[UIViewController alloc] init];

        

        //创建一个label

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 50)];

        

        label.backgroundColor = [UIColor lightGrayColor];

        //根据宽度调整字体大小

        //让文字大小自动适应label

        label.adjustsFontSizeToFitWidth = YES;

        //设置文本

        label.text = @"I'm a label ssssssssss";

        //设置系统字体的大小  默认大小 17 磅 pi

        label.font = [UIFont systemFontOfSize:34];

        //获取系统的字体  Helvetica Neue

        NSLog(@"%@", [UIFont familyNames]);

        //根据字体名字设置字体

        label.font = [UIFont fontWithName:[UIFont familyNames][74] size:34];

        //设置字体为粗体      xingkai.ttf  2,3m

        label.font = [UIFont boldSystemFontOfSize:34];

        //设置字体为斜体

        label.font = [UIFont italicSystemFontOfSize:34];

        //NSString

        //attributedString  富文本

        //设置字体的颜色

        label.textColor = [UIColor redColor];

        //文字的阴影

        label.shadowColor = [UIColor blackColor];

        //文字阴影的方向和长度

        label.shadowOffset = CGSizeMake(3, 3);

        //    label.layer.shadowOpacity = 1;

        //设置文字高亮颜色

        label.highlightedTextColor = [UIColor greenColor];

        //设置高亮状态

        label.highlighted = YES;

        

        //设置文字的对齐方式

        // NSTextAlignmentCenter        居中

        // NSTextAlignmentRight         居右

        label.textAlignment = NSTextAlignmentRight;

        [self.window addSubview:label];

        [label release];

        

        UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(50, 120, 350, 200)];

        label2.backgroundColor = [UIColor lightGrayColor];

        label2.text = @"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.";

        //设置行数 默认 1行  0 表示任意行

        label2.numberOfLines = 0;

        //设置折行模式  以什么方式进行换行

        //NSLineBreakByWordWrapping 以单词为隔断

        //NSLineBreakByCharWrapping 以字符为隔断

        label2.lineBreakMode = NSLineBreakByWordWrapping;

        //自适应label大小

        //    [label2 sizeToFit];

        [self.window addSubview:label2];

        [label2 release];

        

        

        NSString *string = @"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. 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. 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. 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. 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.";

        //(height   1024*8) =

        //根据文字内容计算大小

        // 第1个参数 设置上限的尺寸

        // 第2个参数 换行设置

        // 第3个参数 设置字体  NSFontAttributeName

        // 第4个参数 预留  nil

        CGRect rect = [string boundingRectWithSize:CGSizeMake(350, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17]} context:nil];

        NSLog(@"%@", NSStringFromCGRect(rect));

        label2.text = string;

        CGRect labelRect = label2.frame;

        labelRect.size.width = rect.size.width;

        labelRect.size.height = rect.size.height;

        label2.frame = labelRect;

        

        

        return YES;

    }

  • 相关阅读:
    C# 模拟浏览器请求
    关于获取时间后,时间格式为几天前,几小时前格式转化
    关于通用的C#后台获取前台页面的标签的正则表达式
    关于getHTML()方法和getHtmlAjax()方法 GetHttpLength, 清除HTML标签
    性能测试术语
    聚合报告中90% Line涉及到百分位数的概念
    使用Windows的cmd运行(或通过批处理启动)Python项目(多目录项目)提示找不到模块的解决办法
    OSError: [WinError 6] 句柄无效的解决办法
    python中日志输出重复的解决办法
    截图方法get_screenshot_as_file()注意点
  • 原文地址:https://www.cnblogs.com/chunji/p/5257450.html
Copyright © 2011-2022 走看看