有没有办法以动画方式启用或禁用按钮?我尝试了以下方法但没有成功。我猜测此时启用的属性无法像不透明度那样进行动画 \xe2\x80\x93\xc2\xa0 但我希望我是错的。
\n\n [UIView beginAnimations:nil context:nil];\n [UIView setAnimationDuration:1.0f];\n theButton.enabled = YES;\n [UIView setAnimationDelegate:self];\n [UIView commitAnimations];\nRun Code Online (Sandbox Code Playgroud)\n\n我不敢相信没有一个setEnabled:(BOOL)enabled animated:(BOOL)animated方法。
我知道在stackoverflow上有很多类似的问题,但我的有点不同.我会用图像来展示它,因为它更容易理解.使用这个代码,我从 这里得到了这个结果:

很容易看到屏幕上没有第二个按钮.我尝试了但UIToolbar帧中的负数,但它们不起作用.我不需要任何标题,只能将这些按钮移到左侧.
iphone cocoa-touch objective-c uinavigationbar uibarbuttonitem
我有一个UINavigationController,它的左右按钮属性设置.我没有把标题放在中间,而是想在那里放一个按钮.我不确定我怎么能做到这一点.
码:
UIBarButtonItem* titleButton = [[UIBarButtonItem alloc]
initWithTitle:symbol
style:UIBarButtonItemStyleBordered
target:self
action:@selector(addToWatchlistButtonClicked:)];
self.navigationItem.titleView = titleButton;
Run Code Online (Sandbox Code Playgroud) iphone cocoa-touch objective-c uinavigationbar uibarbuttonitem
这就是我需要的.
我有我的应用程序的免费版本和付费版本.加载付费版本时,我的UIToolBar上需要3个UIBarButtons.当加载免费版本时,我需要4个UIBarButtons.在最右边的barButton,我需要色调蓝色,而其余的默认是黑色.而且我假设他们之间有灵活的空间来平衡他们.我已经尝试通过IB做到这一点,但我似乎无法让它与间距正确.如您所见,带有3个按钮的底部工具栏与工具栏的间距不均匀.(我想以编程方式执行此操作)


#ifdef LITE_VERSION
#else
[buyButton removeFromSuperview];
#endif
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个自定义导航栏按钮项,当用户点击一个函数被调用的条形项时,我有一个选择器.如果我将条形项设置为UIBarButtonItem它只是工作正常但我必须使用自定义图像为按钮没有边框和适当的大小.
所以在viewdidload我打电话
- (void)viewDidLoad
{
[super viewDidLoad];
//gear button on navigation Bar
UIImage* imageback2 = [UIImage imageNamed:@"ICON - Gear-BarstyleItem@2x.png"];
CGRect frameimgback2 = CGRectMake(0, 0, 40, 40);
UIButton *backButton2 = [[UIButton alloc] initWithFrame:frameimgback2];
[backButton2 setBackgroundImage:imageback2 forState:UIControlStateNormal];
[backButton2 addTarget:self
action:@selector(setColorButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithCustomView:backButton2];
UIBarButtonItem *btn3 =[[UIBarButtonItem alloc] initWithImage:imageback2 style:UIBarButtonItemStylePlain target:self action:@selector(setColorButtonTapped:)];
self.navigationItem.rightBarButtonItem = btn2;
}
#pragma mark Callbacks
- (IBAction)setColorButtonTapped:(id)sender{
if (_colorPicker == nil) {
self.colorPicker = [[ColorPickerController alloc] initWithStyle:UITableViewStylePlain];
_colorPicker.delegate = self;
self.colorPickerPopover = [[UIPopoverController …Run Code Online (Sandbox Code Playgroud) objective-c uibutton uibarbuttonitem ios unrecognized-selector
在导航栏中我添加了两个正确的barButtonItems:
[self.navigationItem setRightBarButtonItems:@[firstBarButton,secondBarButton]];
Run Code Online (Sandbox Code Playgroud)
现在当我点击firstBarButtonItem想要删除它.我知道当我只有一个UIBarButtonItem时:
self.navigationItem.rightBarButtonItem = nil;
Run Code Online (Sandbox Code Playgroud)
当rightBarButtonItems是两个时,我该怎么办?
我正在制作一个不使用Interface Builder的应用程序,所以我正在通过代码创建所有内容.
我有一个嵌入在导航控制器中的视图控制器.我知道导航控制器有一个工具栏属性,我需要做的就是将布尔值设置为false以取消隐藏它.我的代码看起来像这样(它是一个在viewDidLoad中调用的函数):
func setUpToolBar(){
navigationController?.toolbarHidden = false
navigationController?.toolbar.barTintColor = UIColor.blackColor()
navigationController?.toolbar.tintColor = UIColor.whiteColor()
toolItems.append(addImageButton)
toolItems.append(UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil))
toolItems.append(exportImageButton)
toolItems.append(UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil))
toolItems.append(deleteImageButton)
navigationController?.toolbar.setItems(toolItems, animated: false)
}
Run Code Online (Sandbox Code Playgroud)
以下是我为视图控制器声明这些属性的位置和方式:
private var addImageButton : UIBarButtonItem = {
let button = UIFactory.createBarButtonItem(nil, imageNamed: "plus button", style: .Plain, target: ImagesCollectionViewController.self, selector: #selector(ImagesCollectionViewController.addImage))
return button
}()
private var exportImageButton : UIBarButtonItem = {
let button = UIFactory.createBarButtonItem(nil, imageNamed: "export button", style: .Plain, target: ImagesCollectionViewController.self, selector: #selector(ImagesCollectionViewController.exportImagePressed))
return button
}() …Run Code Online (Sandbox Code Playgroud) 我有一个工具栏,UIBarButtomItem左边有一个标签Admin
我需要在点击它时显示一个弹出窗口,但它出现在错误的位置,它出现在屏幕的左上角:
这是打开popover的功能:
// this IBAction is assigned only to the Admin bar button item
@IBAction func openAdmin(sender: UIBarButtonItem) {
let alertController = UIAlertController(title: nil, message: "Elige una opción", preferredStyle: .ActionSheet)
// action button initializations... ... ...
let barButtonItemSize = sender.valueForKey("view")
alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = barButtonItemSize!.frame
presentViewController(alertController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
当我触摸管理栏按钮时,我也会在控制台上收到此警告:
快照未呈现的视图会导致空快照.确保在屏幕更新后快照或快照之前至少渲染了一次视图
我究竟做错了什么?或者我需要做什么才能在管理员的顶部显示popover?
我目前有视图控制器 A 和视图控制器 B。
按下按钮时,视图控制器 A 将 vc B 推到它的 navigationController 上:
navigationController?.pushViewController(viewControllerB, animated: true)
VC A 有一个导航栏,上面有一个标题“View Controller A Title”
我希望VC B 有一个左按钮,它是一个后退按钮和一个标题,“视图控制器 B 标题”
目前,当我将 VC B 推到导航控制器上时,VC A 的标题与它一起出现在左后箭头上,所以它看起来像
< View Controller A Title View Controller B Title
我如何摆脱 VC A 标题?
我试过设置左栏按钮项,后栏按钮项,但都没有成功。
我发现删除该标题的唯一方法是
navigationController?.navigationBar.items?.forEach({ $0.title = "" }) 在 VC B 的 viewDidLoad 内部,但是当我单击后退箭头时,VC A 中当然缺少标题
我为上面列出的这个解决方案找到的唯一解决方案是在 VC A 的 viewDidAppear 中设置 navigationItem.title,但是从标题实际显示大约有 1/2 秒的延迟,这并不理想。
有没有更好的方法让这个标题不与导航左栏项目一起出现?
先感谢您!
uinavigationcontroller uibarbuttonitem pushviewcontroller navigationbar swift
我想在 UIBarButtonItem 上放置徽章。为此,我使用以下参考
在此,我创建了“UIBarButtonItem+Badge.swift”文件并将该代码放入其中。在我的视图控制器中,我取了 UIBarButtonItem 的出口。并调用该函数,但它对我不起作用。我的视图控制器文件是这个
我的 UIBarButtonItem+Badge.swift 文件是
extension CAShapeLayer {
func drawRoundedRect(rect: CGRect, andColor color: UIColor, filled: Bool) {
fillColor = filled ? color.cgColor : UIColor.white.cgColor
strokeColor = color.cgColor
path = UIBezierPath(roundedRect: rect, cornerRadius: 7).cgPath
}
}
private var handle: UInt8 = 0;
extension UIBarButtonItem {
private var badgeLayer: CAShapeLayer? {
if let b: AnyObject = objc_getAssociatedObject(self, &handle) as AnyObject? {
return b as? CAShapeLayer
} else {
return nil
}
}
func setBadge(text: String?, withOffsetFromTopRight offset: …Run Code Online (Sandbox Code Playgroud) uibarbuttonitem ×10
ios ×5
iphone ×4
swift ×4
objective-c ×3
cocoa-touch ×2
uitoolbar ×2
xcode ×2
animation ×1
button ×1
navbar ×1
uibutton ×1
uipopover ×1