[英]Removing text label/button on compile time/runtime on Xcode
我想知道是否有任何方法可以在編譯時刪除按鈕文本或標簽文本。
我有一個從服務器下載內容數據的視圖,所以在請求發生的同時我想要空文本,我想保留我在 xcode 上使用的文本,只是在 Xcode 上,以便於查找視圖並在開發時對我的 Xcode 有更多描述性視圖。
現在,對於我想要執行的每個視圖,我使用“用戶定義的運行時屬性”將文本值設置為空字符串,但我想知道是否有更好的方法來做到這一點。
謝謝
在 viewWillAppear 方法上設置文本為空
[btnDontHaveAnAccountYet setTitle:@"" forState:UIControlStateNormal]
當你得到回應而不是重置按鈕標題。
問題解決無需設置運行時文本。
要不然
當你把它放在 xib/Viewcontroller 中時,只保留空白按鈕文本。
你可以使用任何你喜歡的東西,兩者都很容易,而且都在工作。
這個怎么樣?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self removeLabelsFrom:self.view];
}
- (void) removeLabelsFrom:(UIView *)view {
for (UIView *subView in view.subviews) {
if ([subView isKindOfClass:[UIButton class]]) {
UIButton *button;
button = (UIButton *)subView;
[button setTitle:@"" forState:UIControlStateNormal];
} else {
if ([subView isKindOfClass:[UILabel class]]) {
UILabel *label;
label = (UILabel *)subView;
label.text = @"";
} else {
if (subView.subviews.count > 0) {
[self removeLabelsFrom:subView];
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.