Friday, February 24, 2012

Add border to the imageView and textView

Add the border and maker the rounded corner to the imageView and textView:


in .h file
         #import <QuartzCore/QuartzCore.h>
        

in .m file
        // adding border to the imageView
        [theImageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
        [theImageView.layer setBorderWidth: 1.0];

         theImageView.layer.cornerRadius = 9.0;
         theImageView.layer.masksToBounds = YES;
        
        
        // resize the imageView to fit the image size
        CGSize size = [image size];
        float factor = size.width / self.frame.size.width;
        if (factor < size.height / self.frame.size.height) {
            factor = size.height / self.frame.size.height;
        }
        
        CGRect rect = CGRectMake(0, 0, size.width/factor, size.height/factor);
        theImageView.frame = rect;

No comments:

Post a Comment