uibutton

iPhone: Override UIButton buttonWithType to return subclass

梦想与她 提交于 2020-01-11 08:17:26
问题 I want to be able to create a UIButton with an oversized responsive area. I know that one way to do that is to override the hitTest method in a subclass, but how do I instantiate my custom button object in the first place? [OversizedButton buttonWithType: UIButtonTypeDetailDisclosure]; doesn't work out of the box because buttonWithType returns a UIButton, not an OversizedButton. So it seems like I need to override the buttonWithType method as well. Does anyone know how to do this?

How to animate transition from one state to another for UIControl/UIButton? [duplicate]

。_饼干妹妹 提交于 2020-01-11 04:15:07
问题 This question already has an answer here : Fading out an UIButton when touched (1 answer) Closed 6 years ago . I have a UIButton that changes image on highlight. When transitioning from UIControlStateHighlight to UIControlStateNormal, I want the highlighted image to slowly fade back into the normal image. Is there an easy way to do this? 回答1: I ended up subclassing UIButton. Here's the implementation file code. I took some app-specific stuff out, so I haven't tested this exact code, but it

touchesBegin & touchesMove Xcode Obj C Question

纵饮孤独 提交于 2020-01-11 04:00:24
问题 So I have my app working good when you press and drag along. I also have UIButtons set to Touch Down in Interface Builder. As well when you drag you need to drag from the outside of the UIButton. You cannot click on the UIButton and drag to the other. TOUCHES MOVED: Code: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event touchesForView:self.view] anyObject]; CGPoint location = [touch locationInView:touch.view]; if(CGRectContainsPoint(oneButton.frame,

Xcode8 cannot connect multiple/single uibuttons to single @IBAction in swift file

让人想犯罪 __ 提交于 2020-01-10 22:30:16
问题 I am using Xcode 8 beta. I cannot drag multiple UIButtons from storyboard to connect to a single @IBAction in swift file. Bug? Thanks for your help. 回答1: By Using this workaround you can add existing action and also can connect multiple buttons to a single action. I think there is a bug in Xcode8. You can add multiple/Single button to a single action /function by changing sender to _ sender eg :- Normal Button @IBAction func huu(sender: UIButton) { } You can't add multiple buttons or single

UIButton: Making the hit area larger than the default hit area

南楼画角 提交于 2020-01-08 11:21:06
问题 I have a question dealing with UIButton and its hit area. I am using the Info Dark button in interface builder, but I am finding that the hit area is not large enough for some people's fingers. Is there a way to increase the hit area of a button either programmatically or in Interface Builder without changing the size of the InfoButton graphic? 回答1: Since I am using a background image, none of these solutions worked well for me. Here is a solution that does some fun objective-c magic and

UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用

元气小坏坏 提交于 2020-01-07 08:20:33
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> UIButton内有两个控件titleLabel和imageView,可以用来显示一个文本和图片,这里的图片区别于背景图片。给UIButton设置了title和image后,它们会图片在左边,文本在图片右边显示。它们两个做为一个整体依赖于button的contentHorizontalAlignment居左居右或居中显示。 1.当button.width < image.width时,只显示被压缩后的图片,图片是按fillXY的方式压缩。 2.当button.width > image.width,且 button.width < (image.width + text.width)时,图片正常显示,文本被压缩。 3.当button.width > (image.width + text.width),两者并列默认居中显示,可通过button的属性contentHorizontalAlignment改变对齐方式。 4.想两改变两个子控件的显示位置,可以分别通过setTitleEdgeInsets和setImageEdgeInsets来实现。需要注意的是,对titleLabel和imageView设置偏移,是针对它当前的位置起作用的,并不是针对它距离button边框的距离的。我测试下来

UIButton如何正确调整imageView及titleLabel的位置

前提是你 提交于 2020-01-07 07:43:52
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> UIImage *buttonImage = [UIImage imageNamed:@"daifukuan-ico"]; CGFloat buttonImageViewWidth = CGImageGetWidth(buttonImage.CGImage); CGFloat buttonImageViewHeight = CGImageGetWidth(buttonImage.CGImage); if ([UIScreen mainScreen].scale == 2.0f) {// iOS 4.0+ buttonImageViewWidth *= 0.8f; buttonImageViewHeight *= 0.8f; } NSString *buttonTitle = @"中华人"; UIFont *buttonTitleFont = [UIFont systemFontOfSize:14.0f]; CGSize buttonTitleLabelSize = [buttonTitle sizeWithFont:buttonTitleFont]; // button宽度,至少为imageView宽度与titleLabel宽度之和 CGFloat buttonWidth =

Making a Transparent image button with bgcolor

瘦欲@ 提交于 2020-01-07 03:09:06
问题 I have a transparent image which ("hold_empty.png", below) which I want to turn into a button. Inside the button there will be a view with a colored background which is slightly smaller size than the actual image to hold the background color. The reason for this is because the image has rounded corners and so I cannot simply put a background color on the image as it will appear to be bigger than the image. The image is a transparent square with "rounded corners". The effect I am trying to

Enable/Disable button using webViewDidFinishLoad

纵饮孤独 提交于 2020-01-07 02:33:23
问题 I'm working on an iOS app, and I need to prevent a UIButton from being usable until the page has finished loading (it uses resources that might not be on the page until it has loaded completely). Right now, I've disabled the button in Interface Builder and am trying to use setEnabled in the webViewDidFinishLoad function. Here's what it looks like: - (void)webViewDidFinishLoad:(UIWebView *)webView { [activityIndicator stopAnimating]; [randomButton setEnabled:YES]; } The activityIndicator stops

UIButton EXC_BAD_ACCESS error

不问归期 提交于 2020-01-06 18:37:08
问题 I have an UI button and it works correctly when I pressed. But if I press the button three times, I get an EXc_BAD_ACCESS error. I thought I release something in somewhere but I couldn't find the solution. Could you please help me? Kind regards. This is the function when I pressed the button. And in dealloc I release them. When I am tracking, it doesn't give the error in function. I got it after function, but I dont know where the code goes after this function. - (IBAction) doSomething: (id