gpt4 book ai didi

iphone - 具有固定大小自定义图像的 UIButton

转载 作者:可可西里 更新时间:2023-11-01 04:31:34 27 4
gpt4 key购买 nike

我有一个自定义的 UIButton,如下所示:

 UIButton * action = [UIButton buttonWithType:UIButtonTypeCustom];
[action setSize:CGSizeMake(30, 30)];
[action setBackgroundImage:[UIImage imageNamed:@"contextaction.png"] forState:UIControlStateNormal];
[action setContentMode:UIViewContentModeCenter];
[action addTarget:self action:@selector(actionButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

我拥有的真实图像实际上大小为 10x10,居中,我希望它保持这种状态,而不是缩放到按钮大小。我该怎么做?

修改后的代码:

UIButton * action = [UIButton buttonWithType:UIButtonTypeCustom];
[action setSize:CGSizeMake(44, 44)];
[action setImage:[UIImage imageNamed:@"contextaction.png"] forState:UIControlStateNormal];
[action addTarget:self action:@selector(actionButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

if (IS_IPAD){
action.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
action.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
}
actionButton_ = [[UIBarButtonItem alloc] initWithCustomView:action];

仍在扩展

最佳答案

为此,我认为您需要使用图像插入属性 UIButton Class Reference

关于iphone - 具有固定大小自定义图像的 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9711437/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com