How to realize the clipping of the image of the chat software?
Objective-c:
<pre name= "code" class= "OBJC" >-(void) viewdidload {
[super viewdidload];
Uiimageview *imageview01 = [[Uiimageview alloc] init];
[ImageView01 Setframe:cgrectmake (190, 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 no additional setup after loading the view, typically fro M a nib.
var imageview01 = Uiimageview (Frame:cgrectmake (190, 180))
Imageview01.image = UIImage (named: "Style.jpg") C4/>self.view.addsubview (imageview01)
var imageview02 = Uiimageview (frame:imageview01.frame)
Imageview02.image = UIImage (named: "Icon_chat_right_bg")? Stretchableimagewithleftcapwidth (topcapheight:15)
var layer = Imageview02.layer
layer.frame = CGRect ( origin:cgpointzero,size:imageview02.layer.frame.size)
imageview01.layer.mask = Layer
}
Style.jpg:
:
ICON_CHAT_RIGHT_BG: