如何在UITextView中的文本末尾放置一个按钮?

时间:2020-09-02 16:07:41

标签: ios

我真的想不出一种在UIButton文本末尾放置自定义UITextView的方法。不是其结尾,不是其框架,而是其文本。

如果我只能使用UILabel,那么我可以使用TTTAttributedLabel来实现此功能。

我的目标就是这样,而不仅仅是简单的隐藏/显示“读取更多”功能或其他任何功能。


这是目标:

enter image description here


这是一个简单的代码,我现在正在使用frame进行一些实验,而不是使用约束-而且,如果我什至不知道约束按钮的位置,我也看不到约束的使用。

 UIImage *toggleDescriptionFieldButtonImage = self.isFieldDescriptionShown ?
  [UIImage imageNamed:@"ic_field_desc_shown"] : [UIImage imageNamed:@"ic_field_desc_hidden"];
  
  toggleDesciptionFieldButton = [UIButton buttonWithType:UIButtonTypeCustom];
  toggleDesciptionFieldButton.frame = CGRectMake(0, 0, 25, 25);
  [toggleDesciptionFieldButton setImage:toggleDescriptionFieldButtonImage forState:UIControlStateNormal];
  [toggleDesciptionFieldButton addTarget:self
                                  action:@selector(toggleDescriptionFieldPressed:)
                        forControlEvents:UIControlEventTouchUpInside];

0 个答案:

没有答案