IOS pictures of chat bubbles show objective-c and Swift, how to implement a chat software picture showing the cropped bubbles after it!!!

Source: Internet
Author: User

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:





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.