我想在左上角和右上角添加一個圓角到UISearchBar。爲什麼mask不能在UISearchBar上工作
但是,我發現遮罩層不能在UISearchBar上工作,無論我如何設置它。
這裏是我的代碼
// UIView* bar = [searchBar_.subviews objectAtIndex:0]; // try to add mask to background view but also failed
UIView* bar = searchBar_;
CGRect toolbarBounds = bar.bounds;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect: toolbarBounds
byRoundingCorners:UIRectCornerTopLeft
cornerRadii:CGSizeMake(5.0f, 5.0f)];
[maskLayer setPath:[path CGPath]];
[maskLayer setFillColor:[[UIColor greenColor] CGColor]];
bar.layer.masksToBounds = YES;
bar.layer.mask = maskLayer;
我也曾嘗試「剪輯子視圖」,但它也不管用。
然後我嘗試了更多,我只是設置背景視圖(子視圖0)隱藏。令人驚訝的是,它仍然可見。
UISearchBar中有沒有什麼魔法? 該面罩在UIToolbar上工作。
你試過`view.layer.cornerRadius`嗎? – 2011-02-07 11:19:11