UISearchBar去掉背景

2021-09-08 00:05:07 字數 754 閱讀 5076

seachbar=[[uisearchbar alloc] init]; 

//修改搜尋框背景 

seachbar.backgroundcolor=[uicolor clearcolor]; 

//去掉搜尋框背景 

//1. 

[[searchbar.subviews objectatindex:0]removefromsuperview]; 

//2. 

for (uiview *subview in seachbar.subviews) 

} //3自定義背景 

uiimageview *imageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"40-di.png"]]; 

[mysearchbar insertsubview:imageview atindex:1]; 

[imageview release]; 

//4輸入搜尋文字時隱藏搜尋按鈕,清空時顯示 

- (bool)searchbarshouldbeginediting:(uisearchbar *)searchbar   

- (bool)searchbarshouldendediting:(uisearchbar *)searchbar   

//改變搜尋按鈕文字 

//改變uisearchbar取消按鈕字型 

for(id cc in [searchbar subviews])  } 

修改UISearchBar背景

uisearchbar是由兩個subview組成的,乙個是uisearchbarbackground,另乙個是uitextfield.要ib中沒有直接操作背景的屬性,在此我總結了幾個方法去假改它。1.只顯示uitextfield.採用了layer mask.如下 2.隱藏背景。非官方的方法。for ...

設定UISearchBar透明背景

當設定uisearchbar的時候發現無論是通過 searchb.translucent yes 還是 searchb.backgroundcolor uicolor clearcolor 都無法將searchbar的背景設定為透明的。在stackoverflow中發現了乙個方法 for uivie...

UISearchBar控制項

uisearchbar屬性相關 searchbar uisearchbar alloc initwithframe cgrectzero 初始化,不解釋 self.searchbar setplaceholder search 搜尋框的佔位符 self.searchbar setprompt pro...