工具类(设置控件 frame) - iOS
为了便于日常开发效率,因此创建了一些小的工具类便于使用.
具体 code 如下:
声明:
#import <UIKit/UIKit.h> @interface UIView (Frame) @property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, assign) CGFloat centerX;
@property (nonatomic, assign) CGFloat centerY;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGSize size;
@property (nonatomic, assign) CGPoint origin; @end
实现:
#import "UIView+Frame.h" @implementation UIView (Frame) - (void)setX:(CGFloat)x
{
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
} - (void)setY:(CGFloat)y
{
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
} - (CGFloat)x
{
return self.frame.origin.x;
} - (CGFloat)y
{
return self.frame.origin.y;
} - (void)setCenterX:(CGFloat)centerX
{
CGPoint center = self.center;
center.x = centerX;
self.center = center;
} - (CGFloat)centerX
{
return self.center.x;
} - (void)setCenterY:(CGFloat)centerY
{
CGPoint center = self.center;
center.y = centerY;
self.center = center;
} - (CGFloat)centerY
{
return self.center.y;
} - (void)setWidth:(CGFloat)width
{
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
} - (void)setHeight:(CGFloat)height
{
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
} - (CGFloat)height
{
return self.frame.size.height;
} - (CGFloat)width
{
return self.frame.size.width;
} - (void)setSize:(CGSize)size
{
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
} - (CGSize)size
{
return self.frame.size;
} - (void)setOrigin:(CGPoint)origin
{
CGRect frame = self.frame;
frame.origin = origin;
self.frame = frame;
} - (CGPoint)origin
{
return self.frame.origin;
} @end
以上便是此次分享的内容,期待大神多多指点补充,使其更加强壮!
工具类(设置控件 frame) - iOS的更多相关文章
- 我的QT5学习之路(三)——模板库、工具类和控件(下)
一.前言 作为第三篇的最后一部分,我们来看一下Qt的控件,谈到控件,就会让人想到界面的美观性和易操作性,进而想到开发的便捷性.作为windows界面开发的MFC曾经是盛行了多少年,但是其弊端也随着其他 ...
- 工具类(为控件设置圆角) - iOS
为了便于日常开发效率,因此创建了一些小的工具类便于使用.具体 code 如下:声明: /* 为控件添加边框样式_工具类 */ #import <UIKit/UIKit.h> typedef ...
- 工具类(为控件设置色值) - iOS
为了便于日常开发效率,因此创建了一些小的工具类便于使用.具体 code 如下:声明: /* 为控件设置色值 */ #import <UIKit/UIKit.h> @interface UI ...
- Chapter2:Qt5模板库,工具类及控件
2.1 字符串类 QString类保存16位Unicode值,提供了丰富的操作,查询和转换等函数. (1):QString提供了一个二元的"+"操作符用于组合两个字符串 (2) ...
- IOS 制作动画代码和 设置控件透明度
方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...
- <iOS小技巧>UIview指定设置控件圆角
一.用法: 众所周知,设置控件的圆角使用layer.cornerRadius属性即可,但是这样设置成的结果是4个边角都是圆角类型. 利用班赛尔曲线画角: //利用班赛尔曲线画角 UIB ...
- WPF:DataTemplateSelector设置控件不同的样式
原文 WPF:DataTemplateSelector设置控件不同的样式 最近想实现这么个东西,一个ListBox, 里面的ListBoxItem可能是文本框.下拉框.日期选择控件等等. 很自然的想到 ...
- VB.NET设置控件和窗体的显示级别
前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...
- Android线程中设置控件
在Android中经常出现多线程中设置控件的值报错的情况,今天教大家封装一个简单的类避免这样的问题,同样也调用实现也非常的方便. 自定义类: /** * Created by wade on 2016 ...
随机推荐
- Java判断文件、文件夹是否存在
在完成工作室任务的时候多次遇到这个问题,这是一个常用的知识点,记录如下: 1.判断文件是否存在,不存在则创建文件 File file=new File("C:\\2.jpg"); ...
- 调试.NET程序OutOfMemoryException (转载)
原文地址:http://blog.csdn.net/directionofear/article/details/8009427 应用程序调试,需要有个常规的调试思路,应对各类问题最基本的调试手段是什 ...
- Topcoder SRM 563 Div1 500 SpellCards
题意 [题目链接]这怎么发链接啊..... 有\(n\)张符卡排成一个队列,每张符卡有两个属性,等级\(li\)和伤害\(di\). 你可以做任意次操作,每次操作为以下二者之一: 把队首的符卡移动到队 ...
- caffe-windows之网络描述文件和参数配置文件注释(mnist例程)
caffe-windows之网络描述文件和参数配置文件注释(mnist例程) lenet_solver.prototxt:在训练和测试时涉及到一些参数配置,训练超参数文件 <-----lenet ...
- js贪食蛇
<!DOCTYPE html><head><title>canvas贪食蛇</title><style>.canvas{ backgr ...
- 在 Eclipse Juno 上安装 Marketplace
Select Help/Install new software... from the menu, select the Juno update site (http://download.ecli ...
- Cloud
Cloud = Data + Routing + Computing + Storage
- 【起航计划 032】2015 起航计划 Android APIDemo的魔鬼步伐 31 App->Search->Invoke Search 搜索功能 Search Dialog SearchView SearchRecentSuggestions
Search (搜索)是Android平台的一个核心功能之一,用户可以在手机搜索在线的或是本地的信息.Android平台为所有需要提供搜索或是查询功能的应用提 供了一个统一的Search Framew ...
- Class.forName(),classloader.loadclass用法详解
为什么要把ClassLoader.loadClass(String name)和Class.forName(String name)进行比较呢,因为他们都能在运行时对任意一个类,都能够知道该类的所有属 ...
- python 之 BeautifulSoup标签查找与信息提取
一. 查找a标签 (1)查找所有a标签 >>> for x in soup.find_all('a'): print(x) <a class="sister" ...