iOS关于UILabel 基本属性 背景图片 背景色

下面是来客网 jb51.cc 通过网络收集整理的代码片段。

来客网小编现在分享给大家,也给大家做个参考。

#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,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,400);
//    UIImage *image=[UIImage imageNamed:@"1.jpg"];
//    imageView.image =image;//imageView会根据自身大小改变添加的图片的大小所以不需要额外设置image
//    label.backgroundColor = [UIColor clearColor];
//    label.text [email protected]"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,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,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,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

以上是来客网(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。

以上是来客网为你收集整理的iOS关于UILabel 基本属性 背景图片 背景色全部内容,希望文章能够帮你解决iOS关于UILabel 基本属性 背景图片 背景色所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。