2012-03-14 66 views
0

嗨朋友,我想創建一個視圖,我可以添加文本和按鈕。我想保持序列。就像在文本視圖中,我想添加文本,然後按鈕然後再次文本。 並且還想在同一區域進行編輯。 我可以在UITextview中添加按鈕,但是如何維護我在按鈕之後和任何按鈕之前添加的文本序列? 是否有任何示例代碼?在UITextView中添加按鈕和文本

我被

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
myButton .frame = CGRectMake(100, myTextView.contentSize.height, 90, 30); 
[myButton setTitle:@"button text" forState:UIControlStateNormal]; 
[myTextView addSubview:myButton ]; 

添加按鈕的UITextView,但我能不能這個按鈕後,移動光標。

+0

你們是不是來佈局文本,以便按鈕(S)是內聯與文本,即嵌入文本流?如果是這樣,CoreText可能是可能的,但我不知道任何現有的解決方案。 – FluffulousChimp 2012-03-14 13:47:40

回答

0

你能不能以相同的方式添加UILabel和UITextField控件,每次使用contentSize.height?

+0

不,我想在文本視圖中添加文本 – PJR 2012-03-14 11:57:27

+0

您將不得不在這裏解釋'文本'的含義 - 如果您不是在討論文本或標籤控件,您是否想說要粘貼按鈕在文本視圖的中間,並且文本顯示在文本視圖周圍(在它之前和之後)? – JTeagle 2012-03-14 12:04:49

+0

是................ – PJR 2012-03-14 12:06:28

0

文本視圖的父創建UIView子類,並重寫點擊測試排序是這樣的:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 

    // Check if the touch occurs within a rect or below a certain point 
    BOOL isInsidePassThroughArea = point.y + self.textView.contentOffset.y < 72.f; 
    if (isInsidePassThroughArea) { 
    return [self.contentView hitTest:point withEvent:event]; 
    } 

    return [super hitTest:point withEvent:event]; 
}