Tag: uibutton

带有渐变的UIButton,圆angular,边框和阴影

在网站上有一些类似的问题,但我正在寻找一些具体的,稍有不同的东西。 我遵循这里给出的方向: http : //www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/以子类UIButton为了创build一个generics类,我可以指定渐变颜色,而不是尝试使用静态图像。 我碰到一个问题,button层上的setMasksToBounds将允许A)显示阴影,但也允许渐变图层显示超出圆angular或B)渐变图层剪辑到圆angular,但不允许显示阴影 我对这个问题的解决方法看起来很笨重(尽pipe有效),我想看看是否有人知道一个更好和/或更简洁的方法来完成同样的事情。 这是我的代码: CSGradientButton.h #import <UIKit/UIKit.h> @interface CSGradientButton : UIButton { UIColor *_highColor; UIColor *_lowColor; CAGradientLayer *gradientLayer; CALayer *wrapperLayer; CGColorRef _borderColor; } @property (nonatomic, retain) UIColor *_highColor; @property (nonatomic, retain) UIColor *_lowColor; @property (nonatomic) CGColorRef _borderColor; @property (nonatomic, retain) CALayer *wrapperLayer; @property (nonatomic, retain) CAGradientLayer *gradientLayer; – (void)setHighColor:(UIColor*)color; – (void)setLowColor:(UIColor*)color; […]

使用resizableImageWithCapInsets:button的图像仅适用于状态设置,其他状态显示“空白”

当使用resizableImageWithCapInsets:为UIButton创build一个图像只有正常状态(使用setBackgroundImage:forState :)设置图像的状态工作。 所有其他国家都显示了一个差距,而不是绘制的图像。 UIButton说,如果没有图像设置为特定的状态,正常状态图像将被用于禁用和select状态的覆盖。 这是正常的状态: 这里是选中的状态: 这里是源图片: 这显然是使用我提供的可resize的图像,但图像不绘制resize的区域。 (你可以看到左边和右边,但是被拉伸的中间区域没有被绘制)。 有趣的是,stretchableImageWithLeftCapWidth:topCapHeight:确实有效。 现在这是iOS 5中的一个不推荐的方法,但是在新的API中显示出了差距,我可能会被卡住。 我意识到我可以为每个状态提供更多的图像,但是这样做的目的是为了减less内存占用,另外还增加了对我想要避免的graphicsdevise器的依赖。 // This is the gist of the code being used UIImage* image = [UIImage imageNamed:@"button.png"]; UIEdgeInsets insets = UIEdgeInsetsMake(image.size.height/2, image.size.width/2, image.size.height/2, image.size.width/2); image = [image resizableImageWithCapInsets:insets]; [self.button setBackgroundImage:image forState:UIControlStateNormal]; // Even doing the following results in the same behaviour [self.button setBackgroundImage:image forState:UIControlStateSelected];

我们如何创build一个更大的中心UITabBar项目

我想知道如何创build一个更大的中心UITabBar像下面的镜头? 真的很漂亮!!!!

以编程方式向表格视图单元格添加button。

嘿家伙,我可以添加和删除单元格到我的表格视图。 我想要添加每个单元格的两个button。 有人可以帮我吗? 我find了这个,我找不到任何地方! 我会喜欢一些帮助! 非常感谢! :d

访问cellForRowAtIndexPath之外的自定义单元格属性

我想要一些像下面的图片。 用户可以点击+或 – button,增加或减less的计数显示在UILabel中,即下图中的1。 我知道如何实现自定义表格视图单元格。我知道如何实现select器。 但我需要设置的标签文本按照那个button只是问题。 我怎样才能更新button单击并设置文本的自定义单元格的UILabel 从cellForRowAtIndexPath外添加减法function。 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; static NSString *simpleTableIdentifier = @"ProductListVIICell"; ProductListVIICell *cell = (ProductListVIICell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ProductListVIICell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } ……………………………… cell.btnMinus.tag = indexPath.row; cell.btnPlus.tag = indexPath.row; [cell.btnPlus […]

视网膜显示VS正常显示色差

我正在devise一个自定义button,需要我在UIImageView顶部覆盖一个UIButton 。 UIImageView使用[UIImage stretchableImageWithLeftCapWidth:topCapHeight:]图像和UIButton具有模式图像的背景颜色[UIColor colorWithPatternImage:[UIImage imageNamed:@"buttonPattern.png"]] 我面对的问题是,在iPhone 4上,来自UIButton和UIImageView的图像看起来有稍微不同的颜色,尽pipe它们应该匹配。 在iPhone 3GS上testing相同的东西显示没有颜色差异的正常结果。 此图显示了不同之处: 正如你可以看到它在3GS上看起来很好。 在视网膜显示器上,您可以清楚地看到颜色的差异。 我甚至试图在视网膜显示器上使用低分辨率图像(来自3GS),颜色仍然呈现出不同的颜色。 这是视网膜显示设备中的一个错误吗? 有没有人遇到过这个问题?

iOS – 界面生成器:设置图像时,UIButton标题消失

我已经做了一个项目,我设置一个UIButton既有文字也有一个图像(在界面生成器)。 我创build了另一个项目,我想实现同样的目标,但是当我将button设置为一个图像时,标题消失了(它不会隐藏在图像后面)。 我似乎无法弄清楚为什么这样,如果有人可以在这个问题上谈一谈,我会很感激! 谢谢。

将UIButton作为子视图添加到UITabBar

我正试图在我的应用程序中实现一个隐藏的UITabBar。 我制作了所有的animation,效果非常好。 我只是有一个问题,让我的UIButton“拉标签”显示标签栏。 它不响应触摸事件UIControlEventTouchUpInside。 我把这个pull标签添加到UITabBarController的UITabBar中: – (void)viewDidLoad { [super viewDidLoad]; //Add pull pullButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *image = [UIImage imageNamed:@"TabBarPull.png"]; pullButton.frame = CGRectMake(self.tabBar.frame.size.width – image.size.width, -image.size.height + 3, image.size.width, image.size.height); [pullButton setImage:image forState:UIControlStateNormal]; [pullButton addTarget:self action:@selector(pullBarTapped:) forControlEvents:UIControlEventTouchUpInside]; pullButton.userInteractionEnabled = YES; [self.tabBar addSubview:pullButton]; } 这是标签栏看起来像打开和closures的内容: 编辑:我已经确定,问题是因为button不在UITabBar的框架。 看起来我将不得不把button放在UITabBar之外…animation噩梦。

UIControlState.Normal不可用

以前对于UIButton实例,您可以在UIControlState.Normal传递setTitle或setImage 。 .Normal不再可用,应该使用什么? let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) btn.setTitle("title", for: .Normal) // does not compile (这是一个规范的问答对,以防止与iOS 10和Swift 3相关的UIButton和UIControl更改相关的重复问题泛滥)

将parameter passing给@selector方法

我在表格视图中添加了一个UIButton 。 现在,当我点击一个特定的button,我需要获取该行对应的对象的细节。 [button addTarget:self action:@selector(invite:contactmail:) forControlEvents:UIControlEventTouchUpInside]; 我已经使用这个button的方法; 我怎么能传递参数给这个select器方法? 还是有任何其他的方式来传递参数,当这个button被点击这个方法?