How to stretch Image to fill the Label Width set in Background in UILabel?

前端 未结 2 697
暖寄归人
暖寄归人 2020-12-25 09:24

I have simple View based application. I had taken only UILabel on it.

Following is my code in viewDidLoad:

lblBack.textColor = [UIColo         


        
2条回答
  •  长发绾君心
    2020-12-25 09:45

    Dhiren try this code :

        UIImage *img = [UIImage imageNamed:@"cab.png"];
        CGSize imgSize = testLabel.frame.size;
    
        UIGraphicsBeginImageContext( imgSize );
        [img drawInRect:CGRectMake(0,0,imgSize.width,imgSize.height)];
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        testLabel.backgroundColor = [UIColor colorWithPatternImage:newImage];
    

    I have tested this code.

提交回复
热议问题