我想以编程方式设置navigationItem.titleView的按钮.
我尝试使用以下代码,但没有成功;
UIBarButtonItem *navigationTitleButton = [[UIBarButtonItem alloc] initWithTitle:@"Custom" style:UIBarButtonItemStyleBordered target:self action:@selector(backToHOmePage)]; navigationTitleButton.image = [UIImage imageNamed:@"title.png"]; self.navigationItem.titleView = navigationTitleButton;
Warnng说:从’UIBarButtonItem * __ strong’分配给’UIView *’的指针类型不兼容
解决方法
尝试使用此代码,看看它是否适合您
UIView * container = [[UIView alloc]initWithFrame:CGRectZero]; UIButton * button = [[UIButton alloc]initWithFrame:CGRectZero]; [button addTarget:self action:@selector(backToHOmePage) forControlEvents:UIControlEventTouchUpInside]; [button setimage:[UIImage imageNamed:@"clanak_default.png"] forState:UIControlStatenormal]; [button sizetoFit]; [container addSubview:button]; [button release]; [container sizetoFit]; self.navigationItem.titleView = container; [container release];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。