我向基于iphone视图的应用程序添加了一个uislider控件,并连接了一个文本字段,该字段从滑块获取值。为了适应应用程序中的用户界面颜色,我需要更改滑块的颜色。
通过一点谷歌搜索,我找到了两个这样做的样本(
http://blog.hill-it.be/post/2009/03/23/Pimp-My-UISlider
和
http://developer.apple.com/iphone/library/samplecode/UICatalog/index.html
)但我被卡住了,因为我不确定该从哪里调用代码。
我有一个方法应该返回一个自定义的uislider对象,但是如何重写我通过接口生成器创建的位于sliderviewcontroller.m和sliderviewcontroller.h中的对象?
- (UISlider *)createCustomSlider
{
CGRect frame = CGRectMake(174, 12.0, 120.0, 7.0);
UISlider customSlider = [[UISlider alloc] initWithFrame:frame];
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
customSlider.backgroundColor = [UIColor clearColor];
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"orangeslide.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"yellowslide.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
customSlider.minimumValue = 0.0;
customSlider.maximumValue = 100.0;
customSlider.continuous = YES;
customSlider.value = 50.0;
return customSlider;
}
在.NET中,我通常会有一些由Winforms编辑器生成的代码,然后可以通过创建新对象并分配给现有引用来覆盖这些代码。