我想實現像tumblr這樣的標籤功能。我嘗試過使用UITextfield,並在textfield中爲tags_name添加了UIButtons。如何實現標籤功能,如tumblr
- 如何在第一個背面選擇標籤並在第二個背面將其刪除?
- 應該如何在UITextfield的多行添加標籤?
請爲此功能提出任何解決方案。 這裏是我如何在UItextfield中添加按鈕的代碼。
for (count_value = 1; count_value<=[textfieldarray count]; count_value++)
{
UIButton *button_dish = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button_dish setTag:count_value];
[button_dish.layer setOpacity:0.5];
[button_dish.layer setCornerRadius:4.0f];
[button_dish setUserInteractionEnabled:YES];
[button_dish setShowsTouchWhenHighlighted:YES];
[button_dish setContentMode:UIViewContentModeCenter];
[button_dish setTitleEdgeInsets:UIEdgeInsetsMake(8, 8, 4, 8)];
[button_dish.titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
[button_dish.titleLabel setFont:[UIFont fontWithName:@"Eau-SansBold" size:12]];
[button_dish setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[button_dish setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[button_dish setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button_dish setContentMode:UIViewContentModeScaleAspectFit];
[button_dish setTitle:textfieldarray[count_value-1] forState:UIControlStateNormal];
CGSize expected_Size1 = [textfieldarray[count_value-1] sizeWithFont:button_dish.titleLabel.font constrainedToSize:button_dish.frame.size lineBreakMode:NSLineBreakByWordWrapping];
[button_dish addTarget:self action:@selector(buttonactionmethod:) forControlEvents:UIControlEventTouchUpInside];
left_view_length1 = left_view_length1+expected_Size1.width+16+12;
[iconview1 setFrame:CGRectMake(0, 10, left_view_length1, 24)];
[button_dish setFrame:CGRectMake(x_cordinate1, 2, expected_Size1.width+16, 20)];
x_cordinate1 = x_cordinate1+expected_Size1.width+16+12;
[iconview1 addSubview:button_dish];
[textfield1 setLeftView:iconview1];
}
這裏是tumblr標籤樣本參考圖像, 第一圖像顯示按鈕的上第一後選擇。 第二張圖片顯示了多行標籤。
請給我一些參考和提示。
我反對投下這個問題。幾天前我會問同樣的事情,但還沒有嘗試過代碼。這傢伙有示例代碼和截圖。這是一個有效的問題。 –
即使我不知道,在哪個基礎上人們投票的問題?如果問題沒有顯示任何努力,那麼它會。但在這兒 ? :-( –