Reputation: 1475
I'm trying to create a simple circle view. I did it before, and now for some reason the circle is not precise (image attached). In my code i'm taking the height of the "sliderPin" view, and the half value of it goes for the cornerRadius of its layer. I tried to take the constraint height value of the "sliderPin" view as well, but I got the same results. * The width & height of the view are equal. My code:
[self.sliderPin.layer setBorderColor:borderColor];
[self.sliderPin.layer setBorderWidth:2];
self.sliderPin.clipsToBounds = YES;
self.sliderPin.layer.masksToBounds = YES;
[setCornerRadius:CGRectGetHeight(self.sliderPin.frame) / 2];
Upvotes: 1
Views: 130
Reputation: 15639
Better to use UISlider, with given methods. It might solve your problem.
UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *thumbImage = [UIImage imageNamed:@"thumb.png"];
[[UISlider appearance] setMaximumTrackImage:maxImage
forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage
forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage
forState:UIControlStateNormal];
For Height:
You can customise by inheriting UISlider and over-riding method
- (CGRect)trackRectForBounds:(CGRect)bounds {
CGRect rect = CGRectMake(0, 0, 100, 30);//change it to any size you want
return rect;
}
You can customise more by inheriting respective methods.
Thanks.
Upvotes: 1
Reputation: 24248
Make sure constraints
are not conflicting. If you are using auto layout
, set sliderPin
's width and height equal constraints or aspect ratio 1:1 might solve the problem.
Upvotes: 0