Offset UISlider Min/Max value images

醉酒当歌 提交于 2019-12-12 17:25:24

问题


I'm trying to offset the x/y position of a UISlider's min and max value images. Currently, I'm sublcassing UISlider and am setting the maximum value image like this:

[self setMaximumValueImage:[UIImage imageNamed:@"circle_with_plus"]];

However, I need this image to be closer to the actual UISlider and have little control over visual assets on this project. I've tried using

- (CGRect)maximumValueImageRectForBounds:(CGRect)bounds

However, I'm my min/max value images may change size dynamically so I'm not sure how to properly implement it in this case. Is there a different way to move the asset? Thanks


回答1:


No, there is no other way to reposition the minimum or maximum value images. maximumValueImageRectForBounds: gets invoked every time the slider lays out its subviews, and laying out the subviews happens whenever you change the maximumValueImage, so it is sufficient to do:

@implementation MyCustomSlider

- (CGRect)maximumValueImageRectForBounds:(CGRect)bounds {
  CGRect r = [super maximumValueImageRectForBounds:bounds];
  r.origin.x -= 3;
  return r;
}

@end


来源:https://stackoverflow.com/questions/7032866/offset-uislider-min-max-value-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!