我正在使用xcode 4.6
開發一個應用程序。在這裏我想以編程方式添加UIButton到UIscrollview。這是我遵循的代碼。UIscrollview中的自定義UIButton
UIButton *bt =[[UIButton alloc]initWithFrame:frame];
bt=[UIButton buttonWithType:UIButtonTypeCustom];
[bt setTitle:@"Custom Button" forState:UIControlStateNormal];
[bt addTarget:self action:@selector(userTappedOnLink:) forControlEvents:UIControlEventTouchUpInside];
bt.backgroundColor = [UIColor grayColor];
bt.titleLabel.textColor=[UIColor blueColor];
[self.mainscrollview addSubview:bt];
[self.mainscrollview bringSubviewToFront:bt];
現在的問題是,按鈕消失(技術上它的textcolor變成白色)點擊。我檢查保持UIscrollview顏色爲紅色,該按鈕仍然在視圖中,但我不能得到它的文字顏色改變的原因,我如何撤消DIS。 基本上我想用UIbutton創建一個可點擊的鏈接。 我知道uitextview方法(datadetectortype),但它沒用,因爲我想在鏈接和實際鏈接的標籤中顯示不同的文本。
注意:文本顏色不會變回藍色並且只保留白色。
在此先感謝。
謝謝你的答案..這是一個gr8幫助兄弟!現在完美的作品。 – xrnd 2013-03-21 06:08:49