English 中文(简体)
设置 UIS 部分控制的背景图像
原标题:setting background image of UISegmentedControl

所以我有以下代码 来设置分割控制背景颜色:

UISegmentedControl * segmentedCtrl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 150, 35)];
[segmentedCtrl setBackgroundImage:[UIImage imageNamed:@"btn-gradient-brown"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segmentedCtrl setBackgroundImage:[UIImage imageNamed:@"btn-gradient-brown"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[segmentedCtrl insertSegmentWithImage:[UIImage imageNamed:@"icon-home.png"] atIndex:0 animated:NO];
[segmentedCtrl insertSegmentWithImage:[UIImage imageNamed:@"icon-star.png"] atIndex:1 animated:NO];

一切正常, 除了当我点击段段时, 我可以看到蓝色按钮被突出显示。 我如何禁用此突出显示? 这里截图显示我的问题 :

""https://i.sstatic.net/GFxX9.png" alt="此处的内置图像描述"/"

最佳回答

UISEGENT 控制在两个区段之间有一个分隔符。 使用以下代码, 您可以更改分隔符背景 。

[segmentedCtrl setDividerImage:[UIImage imageNamed:@"divider_selected.png"] forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segmentedCtrl setDividerImage:[UIImage imageNamed:@"divider_normal.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

分隔符_ sective. png 是您用于选定状态的图像。 分隔符_ normal. png 是您用于正常状态的图像 。

希望这能帮上忙...

问题回答

为突出显示状态设置相同的背景图像 :

[segmentedCtrl setBackgroundImage:[UIImage imageNamed:@"btn-gradient-brown"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签