Recreating Segmented Control from iPhone App Store

让人想犯罪 __ 提交于 2019-12-12 05:35:50

问题


I'm trying to recreated an interface similar to the app store, using a navigation bar with a segmented control directly below it. I have the controller and all associated views working perfectly; my problem is that I would like to match the color of my segmented controller to the same color that apple uses in the store. How would I go about achieving this? I've experimented with colorWithRed:green:blue:alpha but with little success. Thanks.


回答1:


You can use:

[mySegmentedControl setSegmentedControlStyle:7];

however it is possible that this will be rejected from the App Store, although I have heard of apps that got through perfectly alright, you will have to make sure though that updates to iOS don't change the number from 7.

Alternatively you set the bar style to UISegmentedControlStyleBar and add a UIImageView behind it with and 1x44px screenshot of the edge of the blue background:

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTitles];
[segmentedControl setFrame:CGRectMake(5, 7, self.view.bounds.size.width - 10, 30)];
[segmentedControl setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[segmentedControl setSegmentedControlStyle:UISegmentedControlStyleBar];
UIImageView *backgroundOfSegmentedControl = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"segmentedControl7Background"]];
[backgroundOfSegmentedControl setFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
[backgroundOfSegmentedControl setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view addSubview:backgroundOfSegmentedControl];
[self.view addSubview:segmentedControl];

The result is not identical, but you won't notice unless you directly compare them next to each other.



来源:https://stackoverflow.com/questions/5128659/recreating-segmented-control-from-iphone-app-store

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