uibutton

Duplicate the UIButton and Move it

跟風遠走 提交于 2020-01-17 03:05:11
问题 I have one UIButton (lets say instance1 ).I have set target method when it moves.So when I try to move(drag) I want to do that create copy of instance1 and that copy button should be moved(dragged).Yes I know that -copy will not support to UIButton .So I used : NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject: sender]; UIButton *buttonCopy = [NSKeyedUnarchiver unarchiveObjectWithData: archivedData]; But the problem is when I am trying to move copy button,its not moving and

Prevent UIButton.imageView from resizing by image

跟風遠走 提交于 2020-01-17 02:31:27
问题 I have a UIButton with a fixed height of 40 (constraint height of 40) where I set an image via code thats an pdf (vectorgraphic) of size 64x64 . The result should be: I have added the image like the following: image = [UIImage imageNamed:@"icon-clear"]; [self setImage:image forState:UIControlStateNormal]; The result I'm getting is: Added a black border to the imageView for better visualisation. The imageView has a final size of 64x40 . The thing that happen, I guess, is that the imageView

Swift Error “UIButton.currentTitle must be used from main thread only”

限于喜欢 提交于 2020-01-16 19:01:18
问题 I just followed this you tube tutorial from the following link: URL: https://www.youtube.com/watch?v=aiXvvL1wNUc I cam across an error saying "UIButton.currentTitle must be used from main thread only" Not really sure how to fix this as I am new to making apps, can anyone help me? Greatly appreciated and thanks in advance! import UIKit import MediaPlayer class GenreButtonScreen: UIViewController { var musicPlayer = MPMusicPlayerController.applicationMusicPlayer @IBAction func genreButtonTapped

UIButton state changing while scrolling the tableview with multiple sections - Swift

萝らか妹 提交于 2020-01-16 13:17:21
问题 I have multiple sections in my tableview with multiple custom cells(cell with radio button, cell with check box and cell with textfield). Problem is under section with radio button, only one radio button should be selectable under radio button section. After selecting, I have tried scrolling, multiple radio buttons are selected. Help much appreciated. class RedioButtonCell: UITableViewCell { var radioButtonDelegate: RedioCellDelegate? var cellindexPath : IndexPath? @IBOutlet weak var

UIButton with custom background loses title

拈花ヽ惹草 提交于 2020-01-16 03:24:12
问题 I was trying to create a custom button, but after setting the image, I noticed that the title disappears, it think this is because I add an image to the button, which overlaps the title. UIImage *pickerBg = [UIImage imageNamed:@"btn_picker.png"]; UIImage *pickerBg_highlighted = [UIImage imageNamed:@"btn_picker_highlighted.png"]; [projectBtn setImage:pickerBg forState:UIControlStateNormal]; [projectBtn setImage:pickerBg_highlighted forState:UIControlStateHighlighted]; Is there another way on

iOS - UIButton

烈酒焚心 提交于 2020-01-16 02:16:52
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIButton : UIControl <NSCoding> @available(iOS 2.0, *) public class UIButton : UIControl, NSCoding 1、UIButton 的创建 Objective-C // 实例化 button 对象 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; // 将 button 添加到 window [self.view addSubview:button]; Swift // 实例化 button 对象 let button:UIButton = UIButton(type: .Custom) // 将 button 添加到 window self.view.addSubview(button) 2、UIButton 的设置 Objective-C // 设置 button 类型 /* UIButtonTypeCustom = 0, // 定制按钮,不带图标(常加载图片),默认文字颜色为白色,无触摸时的高亮效果 UIButtonTypeSystem // 不带图标,默认文字颜色为蓝色,有触摸时的高亮效果

UIButton 应用选择状态(附:UIButton 常用状态)

爷,独闯天下 提交于 2020-01-16 02:16:20
NSString * path = [[NSBundle mainBundle]pathForResource:@"alien" ofType:@"png"]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]; NSString* path2 = [[NSBundle mainBundle]pathForResource:@"spider" ofType:@"png"]; UIImage * image2 =[[UIImage alloc]initWithContentsOfFile:path2]; //创建两张图片 UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; [button setBackgroundImage:image forState:UIControlStateNormal];//设置正常状态 [button setBackgroundImage:image2 forState:UIControlStateSelected];//设置选择状态 [button addTarget:self action:@selector(click:) forControlEvents

IOS UIButton用法详解

冷暖自知 提交于 2020-01-16 02:15:57
这段代码动态的创建了一个UIButton,并且把相关常用的属性都列举了.希望对大家有用. //这里创建一个圆角矩形的按钮 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // 能够定义的button类型有以下6种, // typedef enum { // UIButtonTypeCustom = 0, 自定义风格 // UIButtonTypeRoundedRect, 圆角矩形 // UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用 // UIButtonTypeInfoLight, 亮色感叹号 // UIButtonTypeInfoDark, 暗色感叹号 // UIButtonTypeContactAdd, 十字加号按钮 // } UIButtonType; //给定button在view上的位置 button1.frame = CGRectMake(20, 20, 280, 40); //button背景色 button1.backgroundColor = [UIColor clearColor]; //设置button填充图片 //[button1 setImage:[UIImage imageNamed:@"btng.png"]

UIButton的用法

微笑、不失礼 提交于 2020-01-16 02:15:44
/* 1.样式: 2.状态:UIControlStateNormal=0 常规状态显现 UIControlStateHighlighted=1<<0高亮状态显现 */ UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; button.frame=CGRectMake(170, 200, 70, 70); //button.backgroundColor=[UIColor blackColor]; //设置常规标题 [button setTitle:@"登录" forState:UIControlStateNormal]; [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; //设置button上的字体大小 button.titleLabel.font=[UIFont systemFontOfSize:18]; //设置高亮标题 // [button setTitle:@"高亮" forState:UIControlStateHighlighted]; // [button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted]; /

iOS UIButton选中状态切换

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-16 02:15:10
UIButton*payBtn = [UIButtonbuttonWithType:UIButtonTypeCustom]; payBtn.frame=CGRectMake(size.width-24-15,13,24,24); payBtn.tag= j +1; [payBtnsetImage:IMG(@"selectNo")forState:UIControlStateNormal]; [payBtnsetImage:IMG(@"selectNo")forState:UIControlStateHighlighted]; [payBtnsetImage:IMG(@"selectYes")forState:UIControlStateSelected]; [payBtnsetImage:IMG(@"selectYes")forState:UIControlStateSelected|UIControlStateHighlighted]; [payBtnaddTarget:selfaction:@selector(selectPayStyle:)forControlEvents:UIControlEventTouchUpInside]; [payStyleLabeladdSubview:payBtn]; - (void)selectPayStyle:(UIButton*)btn{