最近一个项目有获取手机短信跟邮箱验证码功能, 所以要加一个UIButton倒计时功能 例子代码如下: 1 //获取验证码按钮 2 - (IBAction)getButtonClick:(UIButton *)sender; 3 4 #pragma mark - 获取验证码 5 - (IBAction)getButtonClick:(UIButton *)sender 6 { 7 / UIColor *mainColor = [UIColorcolorWithRed:84/255.0green:180/255.0blue:98/255.0alpha:1.0f]; 9 //倒计时状态下的颜色 获取验证码"countDownTitle:@"s"mainColor:mainColor countColor:countColor]; 12 } 13 14 #pragma mark - button倒计时 15 - (void)setTheCountdownButton:(UIButton *)button startWithTime:(NSInteger)timeLine title:(NSString
UIButton控件是应用界面中常用的一个控件,用法总结: 一、初始化 UIButton的初始化一般使用其类方法,+ (id)buttonWithType:(UIButtonType)buttonType
个人网站、项目部署、开发环境、游戏服务器、图床、渲染训练等免费搭建教程,多款云服务器20元起。
UIButton 的全面解析 建议收藏,用到的时候来这里一查就都明白了 //初始化Button 不用alloca init 的方法 用便利构造器初始化 UIButton *button = [UIButton
//按钮初始化类方法 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];//这里创建一个圆角矩形的按钮 //按钮初始化实例方法 UIButton *button1=[[UIButton alloc]initWithFrame:CGRectMake(50, 300, 200, 50)]; //能够定义的button类型有以下6 是否在dealloc中对UIButton对象进行release操作,取决于UIButton初始化的方式。 如果使用 [[UIButton alloc]init]的方式,则需要主动进行release释放操作。 设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用: [btn.titleLabel setTextColor:[UIColorblackColor]]; btn.titleLabel.textColor
textField.borderStyle = UITextBorderStyle.line // textField.clearButtonMode = .whileEditing let btnLeft:UIButton = UIButton(type:UIButtonType.custom) btnLeft.frame = CGRect(x:0,y:0,width:30,height:30) btnLeft.setBackgroundImage UIControlState()) textField.leftView = btnLeft textField.leftViewMode = .unlessEditing let btnRight:UIButton = UIButton(type:UIButtonType.custom) btnRight.frame = CGRect(x:0,y:0,width:30,height:30) textField.rightViewMode UITextField)-> Bool { textField.resignFirstResponder() return true } func touchupInsideBtnAction(_ btn:UIButton
#import <UIKit/UIKit.h> @interface UIButton (MutableTitle) /** * 根据添加的title 改变 button 的长度 * * @ NSString *)text textFont:(UIFont *)textFont forState:(UIControlState)UIControlState; @end #import "UIButton +MutableTitle.h" @implementation UIButton (MutableTitle) - (void)setMutableTitleWithString:(NSString maxSize lineBreakMode:NSLineBreakByCharWrapping]; } return textSize; } @end 使用时 导入头文件 #import "UIButton +MutableTitle.h" UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 40)]; button.center
第一、UIButton的定义 UIButton *button=[[UIButton buttonWithType:(UIButtonType); 能够定义的button类型有以下6种, typedef
设置无限次循环 [animationImageView startAnimating];//开始播放 //[animationImageView stopAnimating];//停止播放 UIButton 但需要实现一个有点击事件的视图的时候,而这个视图内部的布局有需要自定义,这个时候就可以自定义一个UIButton,然后通过addSubview的方式给自定义的Button添加个性化组件和布局。 之前的时候,遇到上面的需求,我都是子类化一个UIView,然后给该子类添加手势,其实只需要子类化一个UIButton即可,这样就不用自己添加手势了!
在app开发中经常会遇到,输入手机号获取验证码的功能,下面就和大家分享一下,获取验证码倒计时的功能实现 首先给大家看一下页面展示 ? 验证码获取页面 声明属性 @property(strong,nonatomic)UIButton *againBtn; 获取验证码按钮代码 //获取验证码按钮 self.againBtn = [[UIButton setTitleColor:ALLTextColor forState:0]; [self.contentView addSubview:_againBtn]; 按钮点击事件 - (void)againBtn:(UIButton *)sender{ //倒计时函数 [self messageTime]; } 倒计时函数 - (void)messageTime { __block int timeout=60; //倒计时时间 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
在app开发中经常会遇到,输入手机号获取验证码的功能,下面就和大家分享一下,获取验证码倒计时的功能实现 首先给大家看一下页面展示 ? 声明属性 获取验证码的按钮属性声明 @property(strong,nonatomic)UIButton *againBtn; 获取验证码按钮代码 SCREEN_WIDTH 屏幕宽度 //获取验证码按钮 self.againBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*2/3-35, 0, SCREEN_WIDTH/3+ setTitleColor:ALLTextColor forState:0]; [self.contentView addSubview:_againBtn]; 按钮点击事件 - (void)againBtn:(UIButton *)sender{ //倒计时函数 [self messageTime]; } 倒计时函数 - (void)messageTime { __block int timeout=60;
---恢复内容开始--- UIButton 既可以显示图片,又可以显示文字,还能随时调整内部位置 系统自带尺寸 storyboard内部调整UIButton属性 ? 状态 ? ? (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR; 自定义UIButton UIButton内部有两个子控件 UILabel和UIImageView 调整控件内部子控件的frame(两种方式) 实现 titleRectForContentRect 和 imageRectForContentRect // 设置imageView的内边距(影响到imageView) @property(nonatomic) UIEdgeInsets imageEdgeInsets; 图片拉伸 UIButton
先了解Hit-Test请看上一篇文章 https://www.jianshu.com/writer#/notebooks/4989829/notes/33140137 定义一个UIButton的Category UIButton+ClickRange.h import <UIKit/UIKit.h> @interface UIButton (ClickRange) /** 自定义响应边界 UIEdgeInsetsMake 3.0 例如:self.btn.hitHeightScale = 3.0; */ @property(nonatomic, assign) CGFloat hitHeightScale; @end UIButton +ClickRange.m #import "UIButton+ClickRange.h" #import <objc/runtime.h> static const char * kHitEdgeInsets kHitWidthScale = "hitWidthScale"; static const char * kHitHeightScale = "hitWidthScale"; @implementation UIButton
UIButton 风格 typedef NS_ENUM(NSInteger, UIButtonType) { UIButtonTypeCustom = 0, UIButtonTypeRoundedRect = UIButtonTypeSystem, // Deprecated, use UIButtonTypeSystem instead }; 简单操作 UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.tag = 100; // 给 Button 加入标记 在不同的方法中使用同一个控件 从父类视图中获取button UIButton *btn = (UIButton *)[self.window viewWithTag:100]; ; // 让 Button 失效 ; } - (void) buttonAction:(UIButton *)sender { sender.backgroundColor = [UIColor redColor]
#import <UIKit/UIKit.h> typedef void(^ButtonBlock)(UIButton* btn); @interface UIButton (Block) /** UIControlEvents)controlEvents; @end //////////////////////////////////////////////////// #import "UIButton +Block.h" #import <objc/runtime.h> @implementation UIButton (Block) static char ActionTag; /** * = [UIColor redColor]; [self.view addSubview:testButton]; [testButton addAction:^(UIButton *btn) { NSLog(@"我被点名了"); }]; [testButton addAction:^(UIButton *btn) {
现在的APP应用中,用手机获取短信验证码是非常常见的一个功能,而往往要求的效果就是在按下获取验证码之后,验证码的按钮开始倒计时,例如30秒后重新获取。 而我们如何来完成这个效果呢,其实很简单,用一个定时器来计时,设置定时器的时间为UIButton的Title,而这个步骤我们一般用多线程的定时器dispatch source来定时产生事件。 #pragma mark - 倒计时获取验证码 -(void)changeTimeOut:(int)timeOut btnTag:(int)btnTag{ __block int timeout _smsCodeBtn=(UIButton*)[self.view viewWithTag:[[NSString stringWithFormat:@"%d",btnTag _smsCodeBtn=(UIButton*)[self.view viewWithTag:[[NSString stringWithFormat:@"%d",(int
SCREEN_HEIGHT = UIScreen.mainScreen().bounds.size.height let kTopViewHeight = SCREEN_HEIGHT * 0.4 //倒计时试图高度 var isPlaying = false class ViewController: UIViewController { //MARK: - 懒加载 //倒计时 = { let button = UIButton(type: (UIButtonType.Custom)) button.frame = CGRectZero = { let button = UIButton(type: (UIButtonType.Custom)) button.frame = CGRectZero func setupUI() { //顶部的背景试图 self.view.addSubview(self.topBackgroundView) // 显示倒计时的
image.png contactAdd infoLight infoDark System detailDisclosure Custom 代码创建UIButton self.btn1Test = UIButton.init(type:UIButtonType.custom) self.btn1Test?.
按天倒计时 HTML代码1: <Script Language="JavaScript"> <! > 距某某开幕式还有 [<script language="JavaScript" type="text/javascript">djs()</script>] 天 精确到秒的javascript倒计时代码 --倒计时Javascript begin--> <script language="JavaScript"> <! --倒计时Javascript end--> <body onload=DigitalTime1()> </body> 按小时倒计时 - 采用系统时间自校验 这次利用系统时间自校验倒计时, 无需手工调校使得倒计时更为精确, 代码及详细注释如下: 00:01:11:00 <input
如果在一个 UIButton 中你设置 setImage并且 setTitle 。你会发现,默认的是 图片在左边,文字在右边。并且这跟 UIButton 的Frame无关。 Paste_Image.png //按钮内容完美居中的方法 # 需要注意的是 这里的图片尺寸会采用图片的原始尺寸,所以要注意把 UIButton的尺寸设置的足够大才可以达到效果,否则会有图片文字重合的现象 UITextField *nameField = [settingAlert textFieldAtIndex:0]; nameField.placeholder = @"试点编号"; 5.iOS在cell中使用倒计时的处理方法 我们可以利用Model的Start时间戳来实现cell中的倒计时。 ? Paste_Image.png 不过这里是另一种实现思路,也挺不错的:iOS在cell中使用倒计时的处理方法 6.列表和网格视图的相互切换 ?
即时通信 IM(Instant Messaging)基于 QQ 底层 IM 能力开发,仅需植入 SDK 即可轻松集成聊天、会话、群组、资料管理能力,帮助您实现文字、图片、短语音、短视频等富媒体消息收发,全面满足通信需要。
扫码关注腾讯云开发者
领取腾讯云代金券