OGeek|极客世界-中国程序员成长平台

标题: iphone - 如何从 UIBarButtonItem 中删除样式? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:32
标题: iphone - 如何从 UIBarButtonItem 中删除样式?

UIBarButtonItem 中使用自定义图形时在 UIToolbar 内,程序会自动将图形变为白色并应用内阴影。如何防止这种自动样式设置并逐字使用我的自定义图形?

screenshot of toolbar



Best Answer-推荐答案


这是通常的做法:

UIImage *buttonImage = [UIImage imageNamed"myImage.png"];     
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

[myButton setImage:buttonImage forState:UIControlStateNormal];
[myButton setImage:buttonImage forState:UIControlStateHighlighted];

UIBarButtonItem *myBtnItem = [[UIBarButtonItem alloc] initWithCustomView:myButton];

[myButton addTarget:self actionselector(someSelector forControlEvents:UIControlEventTouchUpInside];
[myBtn setFrame:CGRectMake(someX, someY, someWidth, someHeight)];
[self.toolbar setItems:[NSArray arrayWithObjects:someBtnItemOne, myBtnItem, someBtnItemThree, nil]];
[myBtnItem release];

如果这没有帮助,能否请您显示用于初始化工具栏和按钮项的代码?

关于iphone - 如何从 UIBarButtonItem 中删除样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8199781/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4