xcode 自定义 UISlider

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3748473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:46:04  来源:igfitidea点击:

Custom UISlider

iphonexcodeios4

提问by Nipun35

How to customize UISlider?(change style,background,...)

如何自定义 UISlider?(更改样式、背景、...)

回答by Nipun35

You can go through thistutorial for customizing the controls.

您可以通过教程来自定义控件。

For customizing UISlider,use this piece of code from this tutorial.

要自定义 UISlider,请使用本教程中的这段代码。

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];

回答by vfn

Read the documentation: UISliderClass Reference

阅读文档:UISlider类参考

Have a close look at the following methods:

仔细看看以下方法:

Changing the Slider's Appearance

更改滑块的外观

setMinimumTrackImage:forState:
setMaximumTrackImage:forState:
setThumbImage:forState:

For background have a look at UIView documentation.

对于背景,请查看 UIView 文档。

回答by ehenrik

IF you want some example code I could recommend you to look at Apple's example code project UICatalog. This project gives you some basic knowledge about many of the UI elements. In the example they have a custom slider with different colors to the default UISlider.

如果您想要一些示例代码,我可以建议您查看 Apple 的示例代码项目UICatalog。该项目为您提供了有关许多 UI 元素的一些基本知识。在示例中,他们有一个与默认 UISlider 颜色不同的自定义滑块。