对比:UIButton创建方法

[OC]-<UI入门>--常用控件-UIButton 文章目录UIButtonUIButton基础创建文字UIButton设置UIButton 的属性不带图片的UIButton 效果带图片的UIButton带图片的Button创建注意事项及代码解读效果UIButton事件处理事件处理的多个参数先明白参数的意义实现事件事件需要调用的函数(参数之一)效果 UIButton UIButton基础 按钮是所有UI体系中非常重要的组件,在iOS中按钮UIButton的使用也非常灵活 创建文字UIButton 对于UI对象 我们在创建的时候注意一些事项,创建UI对象 阅读详情

Swift

    func addButton(imageName: String,
        highImageName: String,
        disableImageName: String,
        frame: CGRect,
        tag: Int,
        action :Selector){
            // 创建按钮
            let btn = UIButton()
            // 设置背景图片
            btn.setBackgroundImage(UIImage(named: imageName), forState:.Normal)
            btn.setBackgroundImage(UIImage(named: highImageName), forState:.Highlighted)
            btn.setBackgroundImage(UIImage(named: disableImageName), forState:.Disabled)
            // 设置位置和尺寸
            btn.frame = frame
            // 监听按钮点击
            btn.addTarget(self, action: action, forControlEvents: .TouchUpInside)
            // 绑定tag标记
            btn.tag = tag
            // 添加按钮
            self.view.addSubview(btn)
    }

调用方法

        addButton("add",highImageName:"add_highlighted",disableImageName:"add_disabled",frame:CGRectMake(30, 30, 50, 50),tag:10,action:"add")



Objective-C

#pragma mark 添加按钮
- (void)addButtonWithImage:(NSString *)image
                 highImage:(NSString *)highImage
              disableImage:(NSString *)disableImage
                     frame:(CGRect)frame
                       tag:(NSInteger)tag
                    action:(SEL)action
{
    // 创建按钮
    UIButton *btn = [[UIButton alloc] init];
    // 设置背景图片
    [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    [btn setBackgroundImage:[UIImage imageNamed:disableImage] forState:UIControlStateDisabled];
    // 设置位置和尺寸
    btn.frame = frame;
    // 监听按钮点击
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    // 绑定tag标记
    btn.tag = tag;
    // 添加按钮
    [self.view addSubview:btn];
}

调用方法

    [self addButtonWithImage:@"add"
                   highImage:@"add_highlighted"
                disableImage:@"add_disabled"
                       frame:CGRectMake(30, 30, 50, 50)
                         tag:10
                      action:@selector(add)];


UIButton实现setBackgroundColor:ForState功能 在使用UIButton时,很多时候我们需要一个类似于- (void)setBackgroundColor:(UIColor *)color forState:(UIControlState)state这样的方法,来实现在不同的状态下使用不同的backgroundColor。遗憾的是,iOS默认并没有实现这个方法,那我们就自己来实现它。 让我们先来看看对于设置BackgroundImage,U 阅读详情

相关推荐

Objective_C-按钮(UIButton)详解

//1.创建按钮,有多种方法来创建,经常使用的方法是buttonWithType     UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];     //也可以用对象的初始化方法来创建 //    UIButton *button = [[UIButton alloc]init];

京津追梦人 3129

UIButton

创建UIButtonUIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];btn.frame = CGRectMake(30, 360, 90, 35);[btn setTitle:@"ZoomIn"

Luis 9759

K-近邻算法: k-nearest neighbor classification (kNN) 详细介绍

@创建于:2020.04.09 @修改于:2020.04.09,2024.06.22 文章目录1、kNN介绍2、k近邻法的三要素详解2.1 距离度量2.2 k值的选择2.3 分类决策规则3、k近邻法的实现:kd树4、Python实现过程5、优缺点6、常见问题 1、kNN介绍 kNN是一个基本而简单的分类算法,作为监督学习,那么KNN模型需要的是有标签的训练数据,对于新样本的类别由与新样本距离最近的k个训练样本点按照分类...

chenhepg的博客 9万+

IOS -- UIButton 代码创建

// 创建按钮 UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //绘制形状 // 确定宽、高、X、Y坐标 CGRect frame; frame.size.width = 100; frame.size.height = 30; frame.origin.x = 320

xuhuan_wh的专栏 1万+

Spring AI + RAG 构建电商智能客服:从 PDF 文档解析到精准问答的全链路实战

核心框架:向量数据库:- PostgreSQL + pgvector (生产推荐)- Redis Stack (轻量级方案)- ChromaDB (快速原型)文档解析:- Apache PDFBox: PDF 文本提取- Spring AI Document Readers: 结构化解析大模型:- 阿里云百炼 (DashScope)- 本地部署:Qwen/ChatGLM/*** 电商领域实体*/@Data@Builder@ToString/*** 商品类型。

一起修行,不孤单。这里有编程语言、开发工具、学习方法论和踩坑笔记。用简单的话说复杂的事,陪你从小白到进阶。周更干货,欢迎一起成长! 381

python——模拟砍价

类型:随机数。

m0_62488776的博客 1970

你真的会用UIButton吗? UIButton详细介绍

本节知识点: 什么是UIButton UIButton的状态 UIButton的属性设置 UIButton基本使用步骤 UIButton的代码创建与常用属性设置 重写按钮的某个状态属性的 setter 或 getter 方法设置按钮的状态 调整UIButton内部布局 1. 什么是UIButton 还有一个非常重要的UI控件—UIButton,俗称“按钮” 一般情况下,点击某个控件后,会做出相

CD豪 1万+

java调用第三方api接口获取数据

弊端,但是并不是每个接口都适用于这套模板,之前写的接口不适用,都是在这个模板里做了定制处理(if 特殊表 -》处理),需要考虑兼容之前的代码,这种兼容代码,有风险会改掉之前的逻辑个人喜欢,有一个接口,写一段代码灵活自由些。2.还有一部分是对post请求的返回数据,做处理,因为json返回的格式如果双方没有约定好,里面数据是多层json嵌套,需要做处理。江同事交接的就是这个代码模板,可以看下源码调试一下,之前交接的视频,也可以看下,主要还是看代码理解快些,将 写好的代码达成jar包,上传到linux上去,

随风不随水的博客 2036

UIButton 创建

UIButton创建 不能使用 UIButton alloc,因为这样UIButton 的Style是无法设置的。 所以UIButton只有一种创建方法  [UIButton buttonWithType:UIButtonTypeRoundedRect]

cjopengler的专栏 1182

Codex驱动AEDT完成无线充电仿真——从双线圈建模到三维电磁场动画

本文介绍了一个利用Codex、PyAEDT和Ansys Electronics Desktop 2025 R2实现双线圈无线充电系统自动建模与仿真的案例。通过简化模型(平面线圈+铁氧体磁芯),完成了从参数化建模、电磁场求解到后处理的全流程自动化,获得了耦合系数(k=0.17)、三维电磁场分布及多周期动态可视化效果。研究发现:线圈间距对传输效率影响最大(10-30mm间距时效率从40.2%降至5.57%),横向偏移15mm会使效率下降35%,而磁芯厚度增加带来的效率提升有限(3→7mm仅提高1.67%)。该框

sjjsjjsjjsjjsjj的博客 445

如何在 Mac 上下载安装 Xcode——并为 iOS 开发更新它原文

下载 Xcode安装命令行工具打开新版本删除文件注意,我在下面的步骤中列出了一些终端命令。这些命令可以被输入到你现在的工作目录中。这意味着你不需要导航到任何特定的文件夹。如果你真的想这样做,你可以在输入下面的步骤中的命令之前先输入== cd==。这将使你返回到主文件夹。

专注于AI领域前沿知识,业余爱好开发软件 4666

为UIButton添加长按事件的三种方法

实现方法一:重写UIButton, 设置一个代理CustomButtonDelegate @optional -(void)buttonTouchedDown:(UIButton*)button; -(void)buttonTouchedUpOutside:(UIButton*)button; -(void)buttonTouhedCancelled:(UIButton*)button;

Braver_Smile的专栏 2万+

数控系统(CNC)系列:Hurco VMX42SR_(3).控制系统硬件组成部分

控制箱是CNC系统的核心部分,负责处理所有的控制指令和数据。它通常包含主控板、电源模块、接口板等关键组件。伺服驱动器是CNC系统中的关键组件,负责将主控板发出的控制信号转换为电机所需的驱动电流。它通过闭环控制确保电机的精确运动。电机是CNC系统中的执行机构,负责实现主控板发出的运动指令。常见的电机类型包括步进电机和伺服电机。传感器是CNC系统中的重要组件,用于检测和反馈机床的运行状态。常见的传感器类型包括位置传感器、速度传感器、温度传感器等。电源供应系统为CNC系统的所有组件提供电力。主电源。

2401_87715305的博客 1278

UIButton创建不能使用UIButton alloc

UIButton创建不能使用UIButton alloc,因为这样UIButton的Style是无法设置的。 所以UIButton只有一种创建方法  [UIButton buttonWithType:UIButtonTypeRoundedRect]

我是小黑,我要发发。 1659

国债期货的日线趋势跟踪策略实现(基于backtrader框架)

通过backtrader框架,我们可以轻松地实现国债期货的日线趋势跟踪策略,并进行回测和验证。通过这种策略,我们可以尝试捕捉国债期货价格的短期趋势,并根据趋势的方向进行交易决策。backtrader提供了许多内置的指标、订单类型和其他功能,可以帮助你进一步优化和改进你的策略。它提供了丰富的工具和功能,使我们能够快速实现和验证我们的交易想法。方法中,我们根据当前价格和前一天的价格判断趋势的方向,并根据趋势的变化进行买入或卖出操作。然后,我们设置了初始资金和交易手续费,并将我们定义的策略。来跟踪每日的收盘价。

NisyPhilosophy的博客 402

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

更改UIButton的图片颜色

一般我们创建UIButton的时候都是 1. [[UIButton alloc] init]; 2. [UIButton new]; 这两种创建方法. 比如设计给我们的是一张绿色的图.我们某个页面需要弄成白色的话.又得UI重新设计一下图片给我们.挺麻烦的. 查阅文档发现.上面的两种创建方法等同于 [UIButton buttonWithType:UIButtonTypeCustom]; UIB...

MeteoriteMan的博客 6615

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

UI基础UIButton

前面写了UIWindow、UIViewController,那些都是一些框架,框架需要填充上具体的view才能组成我们的应用,移动应用开发中UI占了很大一部分,最基础的UI实现是使用系统提供的各种控件,其他的就是自定义实现了,作者目前是入门状态,只能写写基础控件了。       iOS中提供了UIButton、UILable、UITextField、UIImageView等基础UI控件,继承

风的坚持 491

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

UIButton 基础

@[TOC] UIbutton 基础 创建一个button 注意button只能通过类方法创建,不能使用alloc 该段代码添加在函数- (void)viewDidLoad 中 //通过类方法创建一个UIbutton UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect] ; //设置按钮的位...

吃橘子 5225

UIButton之纯Swift创建及其常见方法

创建UIButton实例对象: let button = UIButton(type: UIButtonType.system) // let button = UIButton(type: .system) 上述构造方法可选值: type: UIButtonType.system type: UIButtonType.close type: UIButtonType.contackAdd type: UIButtonType.custom type: UIButtonType.detailDisclos

kicinio的博客 707

手动创建UIButton 按钮

UIButton * uib = [[UIButton alloc]initWithFrame:CGRectMake(300, 20, 15, 15)];          [uib setBackgroundImage:[UIImage imageNamed:@"clearbutton.png"] forState:UIControlStateNormal];   

zyplove817的专栏 537

创建UIButton

创建UIButton UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame = CGRectMake(30, 360, 90, 35); [btn setTitle:@"ZoomIn" forState:UIControlStateNormal]; [

yuanya的专栏 687

UIButton控件的创建与功能实现

初始化UIButton: 可以用alloc init,也可以用buttonWithType:;纯代码常用后者。- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //1.创建一个圆角矩形的按钮 UIButto

jhb2287759912的博客 346

UIButton的setImage:forState:和setBackgroundImage:forState:方法

setImage:forState: 前置 (覆盖在背景上面的图片,按照之前的尺寸显示) setBackgroundImage:forState: 背景 (背景会填充整个UIButton)

iOS笔记 3702

iOS 开发之 为UIButton添加类别方法加载网络图片

UIButton+WebCache.h   #import     // 为Button添加类别方法   @interface UIButton (WebCache)     - (void)xr_setButtonImageWithUrl:(NSString *)urlStr;   @end   UIButto

糖醋里脊 4688

Swift 创建UIButton

直接上代码看Swift语法下UIButton 的创建 let btn=UIButton.buttonWithType(UIButtonType.System) as! UIButton btn.frame=CGRectMake(50, 60, 200, 36) btn.setTitle("I'm learn Swift", forState: UI

1566
上一篇: 对比:AppDelegate中 application:didFinishLaunchingWithOptions
下一篇: Swift调用系统相机
巴糖
博客等级 码龄12年 8粉丝 55原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值