[代码] iOS关于UILabel 基本属性 背景图片 背景色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#import "ViewController.h"
 
@interface ViewController ()
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
#pragma mark- 一前没见过的几种颜色
//
//     + (UIColor *)lightTextColor;                // for a dark background
//     + (UIColor *)darkTextColor;                 // for a light background
//    
//     + (UIColor *)groupTableViewBackgroundColor;
//    
//     + (UIColor *)viewFlipsideBackgroundColor NS_DEPRECATED_IOS(2_0, 7_0);
//     + (UIColor *)scrollViewTexturedBackgroundColor NS_DEPRECATED_IOS(3_2, 7_0);
//     + (UIColor *)underPageBackgroundColor NS_DEPRECATED_IOS(5_0, 7_0);
//    self.view.backgroundColor=[UIColor scrollViewTexturedBackgroundColor];
#pragma mark- lable基本属性
//    //实例化label对象
//    UILabel *label = [[UILabel alloc]init];
//    //背景颜色
//    label.backgroundColor = [UIColor redColor];
//    //frame大小
//    label.frame = CGRectMake(0, 0, 20, 20);
//    //内容
//    label.text = @"label";
//    //字体大小
//    label.font = [UIFont systemFontOfSize:15];
//    //字体加粗
//    label.font = [UIFont boldSystemFontOfSize:15];
//    //字体斜体  对中文无效
//    label.font = [UIFont italicSystemFontOfSize:15];
//    //文字类型与大小
//    label.font = [UIFont fontWithName:@"Arial" size:30];
//    //文字是否居中  左  右
    /*
     NSTextAlignmentLeft //左对齐
     NSTextAlignmentCenter //居中
     NSTextAlignmentRight  //右对齐
     NSTextAlignmentJustified//最后一行自然对齐
     NSTextAlignmentNatural //默认对齐脚本
     */
//    label.textAlignment = NSTextAlignmentCenter;
//    //文字颜色
//    label.textColor = [UIColor whiteColor];
//    //文字阴影
//    label.shadowColor = [UIColor whiteColor];
//    //文字阴影偏移量
//    label.shadowOffset = CGSizeMake(1, -1);
//    //文字自适应
//    label.adjustsFontSizeToFitWidth = YES;
//    //文本自动换行
//    label.numberOfLines = 0;
//    //label切圆角
//    label.layer.cornerRadius = 5;
//    label.layer.masksToBounds = YES;
//    //文本类型 设置换行模式/省略模式
//    /*
//     NSLineBreakByWordWrapping = 0,
//     NSLineBreakByCharWrapping,
//     NSLineBreakByClipping,
//     NSLineBreakByTruncatingHead,
//     NSLineBreakByTruncatingTail,
//     NSLineBreakByTruncatingMiddle
//     */
//    label.lineBreakMode =NSLineBreakByTruncatingTail;
//    //tag值 标志位
//    label.tag = 1;
//    //高亮状态
//    label.highlighted =YES;
//    //是否开启交互
//    label.userInteractionEnabled = YES;
//    //边框颜色
//    label.layer.borderColor = [UIColor lightGrayColor].CGColor;//边框颜色,要为CGColor
//    //边框宽度
//    label.layer.borderWidth = 1;//边框宽度
//    //自动适应文字  能换行
//    [label sizeToFit];
//     如果设置为No,则文字颜色会变暗,表明其是不可用的,默认值为YES。
//     label.enabled = NO;
#pragma mark- lable加背景图片 第一种 感谢网络大神
//    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 400)];
//    UIImageView *imageView =[[UIImageView alloc]init];
//    imageView.frame =CGRectMake(50, 50, 200, 400);
//    UIImage *image=[UIImage imageNamed:@"1.jpg"];
//    imageView.image =image;//imageView会根据自身大小改变添加的图片的大小所以不需要额外设置image
//    label.backgroundColor = [UIColor clearColor];
//    label.text =@"hello world";
//    label.font = [UIFont systemFontOfSize:30];
//    label.textColor = [UIColor yellowColor];
//    [self.view addSubview:imageView];//添加的顺序不能错,否则图片会覆盖label
//    [self.view addSubview:label];
//   
//
#pragma mark- lable加背景图片 第二种 感谢网络大神
//    UIImage *image=[UIImage imageNamed:@"1.jpg"];
//   UIImage *han = [self scaleImage:image ToSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)];
//    UIColor * color = [UIColor colorWithPatternImage:han];//image为需要添加的背景图
//    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
//    label.text = @"safds";
//    label.font =[UIFont systemFontOfSize:18];
//    label.textColor = [UIColor yellowColor];
//    label.textAlignment = NSTextAlignmentCenter;
//    [label setBackgroundColor:color];
//    [self.view addSubview:label];
#pragma mark- 能显示就显示不能显示就按照原来的大小显示 感谢网络大神
//    float maxHeight =50;//设置最大高度
//    float minFontSize =9;
//    float height;
//    int fontSize = 31;//设置最大字号
//    NSString *text = @"输入文本内容输入文本内容输入文本内容";
//    do {
//        fontSize = fontSize - 1;
//        UIFont *font =[UIFont fontWithName:@"Arial" size:fontSize];
//        CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(100, 210)/*宽度与label的宽度一样,高度应高于label高度*/ lineBreakMode:NSLineBreakByCharWrapping];
//        height = size.height;
//        NSLog(@"height=%f,fontSize=%d,text=%@",height,fontSize,text);
//    } while (height > maxHeight&&fontSize>minFontSize);
//   
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 100, 50)];
//    label.text =text;
//    if (fontSize ==9) {//判断字体是否小于最小字号,小于最小字号时就使用系统默认的缩略显示
//        label.font = [UIFont fontWithName:@"Arial" size:15];
//    }
//    else{
//        label.font = [UIFont fontWithName:@"Arial" size:fontSize];
//        label.lineBreakMode = NSLineBreakByCharWrapping;//实现文字多行显示
//        label.numberOfLines = 0;
//    }
//    [self.view addSubview:label];
}
#pragma mark- lable加背景图片 第二种  感谢网络大神
//-(UIImage *)scaleImage:(UIImage *)img ToSize:(CGSize)itemSize{
//    UIImage *i;
//    // 创建一个bitmap的context,并把它设置成为当前正在使用的context
//    UIGraphicsBeginImageContext(itemSize);
//    CGRect imageRect=CGRectMake(0, 0, itemSize.width, itemSize.height);
//    // 绘制改变大小的图片
//    [img drawInRect:imageRect];
//    // 从当前context中创建一个改变大小后的图片
//    i=UIGraphicsGetImageFromCurrentImageContext();
//    // 使当前的context出堆栈
//    UIGraphicsEndImageContext();
//    // 返回新的改变大小后的图片
//    return i;
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
@end

iOS关于UILabel 基本属性 背景图片 背景色的更多相关文章

  1. UIlabel添加背景图片

    做UI的时候我们可能想给某个Label添加一个背景图片,但查看的时候会发现好像只有设置背景颜色的方法,不过我们也可以通过这种方式来解决: UIColor *color = [UIColor color ...

  2. iOS:让标题栏背景图片适应iOS7

    From google: If your app uses a custom image as the background of the bar, you'll need to provide a ...

  3. IntelliJ IDEA设置主题和背景图片(背景色)

    设置主题以及背景图片 设置代码背景颜色

  4. ios UIButton 选中后背景图片变化发灰问题

    UIButton的类型如果选择了System类型,那么设置背景图后,点击的效果是图片发灰,而不是默认的那种图片变淡黑色效果,需要用customer类型就好了.

  5. ios:设置视图背景图片的方法

    1. 使用一个UIImageView实例做子视图,并且放最后面UIImageView *customBackgournd = [UIImageView alloc] initWithImage:[UI ...

  6. iOS 中 为UIView添加背景图片

    创建UIImage的方法有两种: UIImage *image = [UIImageimageNamed:@"image.jpg"];//这种不释放内存,要缓存 NSString ...

  7. iOS开发备忘录:自定义UINavigationBar背景图片和Back按钮

    iOS项目,根据设计图,有时需要自定义UIView的UINavigationBar的背景.可以切出来一张1像素左右的背景图片,来充当UINavigationBar的背景. 可以利用Navigation ...

  8. Qt setStyleSheet 添加背景色/背景图片(取消背景色,读取本地文件作为背景色)

    容易搞定,mainWindow 是一个QWidget.// 设置背景色为蓝色mainWindow.setStyleSheet("background-color:blue;"); ...

  9. Swift - 设置UIView的背景色和背景图片

    1,使用UIColor的内置颜色设置背景色 1 2 var page = UIView() page.backgroundColor = UIColor.greenColor() 2,设置自定义颜色 ...

随机推荐

  1. ecshop 订单-》设置默认收货地址,或者删除

    设置位置:ecs_users标的   country字段,默认是0,默认地址是 users_address 的address_id 设置默认收货地址 /** * 设置默认地址 * * @access ...

  2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)--MySQL错误

    MySQL错误整理: 错误一: ERROR (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/my ...

  3. Python 之作用域和名字空间

    作用域与名字空间 Python有一个核心概念是名字空间(namespace),namespace是一个name到object 的映射关系,Python有很多namespace,因此,在代码中如果碰到一 ...

  4. AndroidStudio-使用Translations Editor

    前言 如果你的App支持多语言,你需要正确的管理你的翻译字符串资源.Android Studio提供了翻译编辑器使更容易的查看和管理翻译资源. 关于翻译编辑器 翻译资源存储工程的多个目录下的多个XML ...

  5. ThreadStart和ParameterizedThreadStart区别

    ThreadStart: ThreadStart这个委托定义为void ThreadStart(),也就是说,所执行的方法不能有参数. ThreadStart threadStart=new Thre ...

  6. php函数mt_rand和rand 速度测试

    今天在写代码时,看到以前的同时写了一个取随机数,用到了mt_rand(2,19) 就顺手搜了一下,mt_rand和rand的区别. 先看官方的解释 mt_rand 和 rand mt_rand — 生 ...

  7. 如何向git账号上提交代码

    官方说明:https://help.github.com/articles/generating-ssh-keys/ 1,为Github账户设置SSH key 文章地址:http://zuyunfei ...

  8. Java 中浮点数---------BigDecimal和double(初探)

    为什么要使用 bigdecimal? 借用<Effactive Java>这本书中的话,float和double类型的主要设计目标是为了科学计算和工程计算.他们执行二进制浮点运算,这是为了 ...

  9. caller和callee

    我们先来看下caller. caller:返回一个对函数(该函数调用了当前函数)的引用. functionName.caller:functionName对象是所执行函数的名称. 说明 对于函数来说, ...

  10. 【转载】Unity 优雅地管理资源,减少占用内存,优化游戏

    转自:星辰的<Unity3D占用内存太大的解决方法> 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大. 这里写下关于Unity3D对于内存的管理与优化. Unity3D  ...