Date
Oct. 18th, 2024
 
2024年 9月 16日

Post: iOS 小知识: 为 UIView 设置图片

Today is the A Memorial Day

iOS 小知识: 为 UIView 设置图片

Published 12:10 Oct 14, 2014.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

介绍一些 iOS 小知识。

给 UIView 设置图片

  • 方法一
UIImage *image = [UIImage imageNamed:@"<#Your Image#>"];
UIColor *color = [UIColor colorWithPatternImage:image];
UIView *view = [[UIView alloc] initWithFrame:<#CGRect#>];
[view setBackGroundColor:color];
  • 方法二
UIImage *image = [UIImage imageNamed:@"<#Your Image#>"];
UIView *view = [[UIView alloc] initWithFrame:<#CGRect#>];
[view layer].contents = (__bridge id)image.CGImage;
// 显示的范围
[view layer].contentsCenter = CGRectMake(0.25, 0.25, 0.5, 0.5);
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询