【问题标题】:Adding the custom button in the header of UIViewController [closed]在 UIViewController 的标题中添加自定义按钮 [关闭]
【发布时间】:2013-06-27 10:39:37
【问题描述】:

我想在视图控制器的标题中放置一个图标,例如 bbc 新闻应用程序,以最大化和最小化字体。

我必须知道,有没有图书馆可以做到这一点?

【问题讨论】:

  • 需要什么库才能将按钮的背景设置为UIImage
  • 不,我需要它的实现,而不是视图,我知道我可以放一个uiimage的背景,但是这个按钮的作用是什么?
  • 我不知道这个 BBC 按钮在做什么,但我猜他们正在增加文本的字体,因为你可以做的是将 UIWebView 中的内容作为 html 内容加载到某个段落标签中然后连续单击按钮,您可以增加段落的字体大小或减小段落的字体大小,您可以这样做。
  • 我认为,该动作是执行一些 Java Script 代码,因为这是一个 Web 应用程序... 例如:jsCommand = [NSString stringWithFormat: @"document.body.style.fontSize = 24;" ,尺寸]; [webView stringByEvaluatingJavaScriptFromString:@"getSelectedNode().style.fontSize"];

标签: ios


【解决方案1】:

希望对你有所帮助..

UIView *customView=[[UIView alloc]initWithFrame:CGRectMake(10, 0, 40, 40)];

 UIButton *btnAction =[UIButton buttonWithType:UIButtonTypeCustom];
 [btnAction addTarget:self action:@selector(btnActionClick) forControlEvents:UIControlEventTouchDragInside];
 [btnAction setFrame:CGRectMake(0, 0, 40, 58)];
[customView addSubview:btnAction];

 UIButton *btnFont =[UIButton buttonWithType:UIButtonTypeCustom];
 [btnFont addTarget:self action:@selector(btnFontClick) forControlEvents:UIControlEventTouchDragInside];
 [btnAction setFrame:CGRectMake(30, 0, 40, 58)];
 [customView addSubview:btnAction]

 UIBarButtonItem *MessageBtn=[[UIBarButtonItem alloc]initWithCustomView:customView];

【讨论】:

  • 是的,它适用于你的情况......
【解决方案2】:

通过使用以下代码,您可以将按钮放在视图控制器的标题中。

但要设置字体(最小化或最大化),您必须编写其他代码。

你可以为它做谷歌。

[self.navigationItem setRightBarButtonItem:"BUTTON"animated:YES];

【讨论】:

    【解决方案3】:

    你可以使用

    [self.navigationItem setRightBarButtonItem:"your button"animated:YES];
    

    【讨论】:

      猜你喜欢
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 1970-01-01
      • 2017-08-14
      • 2011-02-07
      • 2020-08-11
      • 1970-01-01
      相关资源
      最近更新 更多