0
我想添加漸變UISearchController
不起作用。UISearchController add CAGradientLayer
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.definesPresentationContext = YES;
[self.searchController.searchBar setFrame:CGRectMake(0, 0, self.view.frame.size.width, 79)];
CAGradientLayer * grad = [CAGradientLayer layer];
grad.frame = self.searchController.searchBar.bounds;
grad.colors = @[(id)UIColorFromRGB(0x8daf00).CGColor,
(id)UIColorFromRGB(0xd1af03).CGColor];
[ self.searchController.searchBar.layer insertSublayer:grad atIndex:0];
,你在viewDidLoad中添加此代碼,否則,如果它是在viewDidLoad中改變這viewdidappear –
參考這個鏈接,HTTP://stackoverflow.com/questions/23074539/programmatically-create-a-uiview-與色梯度。 @Luis Teodoro Junior – KAR
漸變是正確的並且工作正常,問題在於UISearchController無法識別漸變。 –