iOS 图片 的 聊天气泡显示 Objective-C 和 Swift,如何实现聊天软件的图片显示的剪裁后的气泡呢!!!

如何实现聊天软件的图片显示的剪裁后的气泡呢
iOS 图片 的 聊天气泡显示 Objective-C 和 Swift,如何实现聊天软件的图片显示的剪裁后的气泡呢!!!_第1张图片



Objective-C:
<pre name="code" class="objc">- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *ImageView01 = [[UIImageView alloc] init];
    [ImageView01 setFrame:CGRectMake(90, 190, 120, 180)];
    [ImageView01 setImage:[UIImage imageNamed:@"style.jpg"]];
    [self.view addSubview:ImageView01];
    
    UIImage *bubble = [UIImage imageNamed:@"icon_chat_right_bg"];
    UIImageView *ImageView = [[UIImageView alloc] init];
    [ImageView setFrame:ImageView01.frame];
    [ImageView setImage:[bubble stretchableImageWithLeftCapWidth:15 topCapHeight:15]];
    
    CALayer *layer              = ImageView.layer;
    layer.frame                 = (CGRect){{0,0},ImageView.layer.frame.size};
    ImageView01.layer.mask = layer;
    [ImageView01 setNeedsDisplay];
}


 
 

Swift:

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        var imageview01 = UIImageView(frame: CGRectMake(90, 190, 120, 180))
        imageview01.image = UIImage(named: "style.jpg")
        self.view.addSubview(imageview01)
        
        var imageview02 = UIImageView(frame: imageview01.frame)
        imageview02.image = UIImage(named: "icon_chat_right_bg")?.stretchableImageWithLeftCapWidth(15, topCapHeight: 15)
        
        var layer = imageview02.layer
        layer.frame = CGRect(origin: CGPointZero,size: imageview02.layer.frame.size)
        imageview01.layer.mask = layer
        
    }



style.jpg:
: iOS 图片 的 聊天气泡显示 Objective-C 和 Swift,如何实现聊天软件的图片显示的剪裁后的气泡呢!!!_第2张图片  

icon_chat_right_bg:





你可能感兴趣的:(Objective-C,图片,swift,聊天图片气泡,iOS聊天气泡)