选取UIButton的文本

时间:2012-01-13 07:41:47

标签: iphone ios uibutton

我有一个UIButton,其文本来自服务器。按钮的宽度是固定的。我想要的是,如果按钮的文本超出按钮的宽度,文本应该是按钮内的选框。如果文本适合按钮宽度,则应该没有选框效果。

我关注了一些链接(onetwo),但我仍然对这个问题感到困惑。我试图实现第一个链接,但没有成功。文字没有动。

这是因为我需要在UIView内取按钮,或者按钮内是否可以移动文字?

2 个答案:

答案 0 :(得分:0)

你可以使用webview进行这项工作,如下所示加载html,你可以使用条件检查文本或多或少,使用href来超链接文本。单击webview委托时,此超链接文本会识别它。

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
                 navigationType:(UIWebViewNavigationType)navigationType;

  <html>
      <body bgcolor=\"#0066CC\">
      <marquee>some test to marquee </marquee>
      </body>
  </html>

答案 1 :(得分:0)

我遇到同样的问题我检查你的2链接和第二个工作在我的情况下。 我正在为你发布我的代码。

messageView = [[UIView alloc] initWithFrame:CGRectMake(20, 680, 635, 19)];
[messageView setClipsToBounds:YES];
[backgroundImageView addSubview:messageView];
 lblTime = [[UILabel alloc] initWithFrame:CGRectMake(900, 680, 635, 19)];// your starting animation point 
[lblTime setBackgroundColor:[UIColor clearColor]]; 
lblTime.textColor=[UIColor whiteColor];
[lblTime setFont:[UIFont boldSystemFontOfSize:15]];
[backgroundImageView addSubview:lblTime];
[self sendNotification:@"your message"]; // call the method


- (void)sendNotification:(NSString*)txt{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:8.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:messageView cache:YES];
[lblTime setText:txt];
[lblTime setTextAlignment:UITextAlignmentLeft];
lblTime.frame = CGRectMake(20, 680, 650, 19); // end point of animation
[UIView commitAnimations];
}