![](/img/trans.png)
[英]how to increase and decrease circle size in uislider with value change
[英]How to increase the size of the max track of a UISlider?
我想添加一個大小從最小到最大不同的 UISlider。
這是我需要的一個例子:
我嘗試使用一些方法,例如:
- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds;
- (CGRect)maximumValueImageRectForBounds:(CGRect)bounds;
- (CGRect)trackRectForBounds:(CGRect)bounds;
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value;
但我無法讓它工作......
關於您如何實現這一目標的任何建議或鏈接?
您需要繼承 UISlider。 如果你在運行時創建 UISlider 你應該使用initWithFrame
否則initWithCoder
。
@implementation slider
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
// At certain point images swap, that is why you need images fit to your UISlider size.
UIImage *sliderLeftImg = [[UIImage imageNamed: @"slider2"] stretchableImageWithLeftCapWidth: 10 topCapHeight: 0];
UIImage *sliderRightImg = [[UIImage imageNamed: @"slider"] stretchableImageWithLeftCapWidth: 10 topCapHeight: 0];
[self setMinimumTrackImage: sliderLeftImg forState: UIControlStateNormal];
[self setMaximumTrackImage: sliderRightImg forState: UIControlStateNormal];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
我繪制的示例圖像草率循環,您需要更好的。
最后結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.