small medium large xlarge

Generic-user-small
29 Oct 2010, 21:00
Luke Rhodes (3 posts)

Hey,

First of all, it’s my first time of writing in the forums so if you read this Bill I thought I’d just say thanks so much for your vids - they’re great!

So the problem I’m having is with a Subclassed UIView object (IconView)

In the IconView I have implemented drawRect:

- (void)drawRect:(CGRect)rect {
    CGRect frame = CGRectMake(0, 0, buttonWidth, buttonWidth);
    [self.backgroundImage drawInRect:frame];
    [self.mainImage drawInRect:frame];
}

The background image stay the same between icons however the mainImage changes based on which icon it is.

The background image is rounded.

It is necessary that sometimes the mainImage may be an image that is larger than the backgroundView. (When highlighted, the IconView is redrawn larger but the mainImage stays the same size)

I used to use the following for which looked right however I’m trying to really optimise code and part of that includes implementing things under the drawRect.

self.mainImageView.layer.cornerRadius = 8;
[self.mainImageView setContentMode:UIViewContentModeScaleAspectFill];
[self.mainImageView setCenter:CGPointMake(CGRectGetWidth(self.mainImageView.frame)/2, CGRectGetHeight(self.mainImageView.frame)/2)];

So with my current drawRect I need to get the same effect. I’ve found a UIImage category that does the rounding however I need a hand with the cropping.

Or… would it be best to create an outline fill path with arcs for corners?

Thanks a lot

Luke

You must be logged in to comment