This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-iOS/Pod/Classes/Shader/UIView+Doric.m

146 lines
3.2 KiB
Mathematica
Raw Normal View History

2019-10-21 09:59:22 +08:00
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2019-07-25 19:56:49 +08:00
//
// UIView+Doric.m
// Doric_Example
//
// Created by pengfei.zhou on 2019/7/25.
// Copyright © 2019 CocoaPods. All rights reserved.
//
#import "UIView+Doric.h"
2020-04-03 16:36:43 +08:00
#import <objc/runtime.h>
static const void *kTagString = &kTagString;
2019-07-25 19:56:49 +08:00
2019-10-12 14:48:19 +08:00
@implementation UIView (Doric)
2020-04-03 16:36:43 +08:00
- (void)setTagString:(NSString *)tagString {
objc_setAssociatedObject(self, kTagString, tagString, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.tag = [tagString hash];
}
- (NSString *)tagString {
return objc_getAssociatedObject(self, kTagString);
}
- (UIView *)viewWithTagString:(NSString *)tagString {
// notice the potential hash collision
return [self viewWithTag:[tagString hash]];
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (CGFloat)x {
2019-07-25 19:56:49 +08:00
return self.frame.origin.x;
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (void)setX:(CGFloat)x {
2019-07-25 19:56:49 +08:00
CGRect frame = self.frame;
frame.origin.x = x;
[self setFrame:frame];
}
2019-07-29 13:48:27 +08:00
- (CGFloat)y {
2019-07-25 19:56:49 +08:00
return self.frame.origin.y;
}
2019-07-29 13:48:27 +08:00
- (void)setY:(CGFloat)y {
2019-07-25 19:56:49 +08:00
CGRect frame = self.frame;
frame.origin.y = y;
[self setFrame:frame];
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (CGFloat)left {
2019-07-25 19:56:49 +08:00
return self.frame.origin.x;
}
2019-07-29 13:48:27 +08:00
- (void)setLeft:(CGFloat)left {
2019-07-25 19:56:49 +08:00
CGRect frame = self.frame;
frame.origin.x = left;
[self setFrame:frame];
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (CGFloat)right {
2019-07-25 19:56:49 +08:00
return self.frame.origin.x + self.frame.size.width;
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (void)setRight:(CGFloat)right {
2019-07-25 19:56:49 +08:00
CGRect frame = self.frame;
frame.origin.x = right - self.frame.size.width;
[self setFrame:frame];
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (CGFloat)top {
2019-07-25 19:56:49 +08:00
return self.frame.origin.y;
}
2019-10-12 14:48:19 +08:00
2019-07-25 19:56:49 +08:00
- (void)setTop:(CGFloat)top {
CGRect frame = self.frame;
frame.origin.y = top;
[self setFrame:frame];
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (CGFloat)bottom {
2019-07-25 19:56:49 +08:00
return self.frame.origin.y + self.frame.size.height;
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (void)setBottom:(CGFloat)bottom {
2019-07-25 19:56:49 +08:00
CGRect frame = self.frame;
frame.origin.y = bottom - self.frame.size.height;
[self setFrame:frame];
}
- (CGFloat)width {
return self.frame.size.width;
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (void)setWidth:(CGFloat)width {
2019-07-25 19:56:49 +08:00
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}
2019-07-29 13:48:27 +08:00
- (CGFloat)height {
2019-07-25 19:56:49 +08:00
return self.frame.size.height;
}
2019-10-12 14:48:19 +08:00
2019-07-29 13:48:27 +08:00
- (void)setHeight:(CGFloat)height {
2019-07-25 19:56:49 +08:00
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}
2019-10-12 14:48:19 +08:00
2019-07-25 19:56:49 +08:00
- (CGFloat)centerX {
2019-10-12 14:48:19 +08:00
return self.frame.origin.x + self.frame.size.width / 2;
2019-07-25 19:56:49 +08:00
}
2019-10-12 14:48:19 +08:00
2019-07-25 19:56:49 +08:00
- (void)setCenterX:(CGFloat)centerX {
CGRect frame = self.frame;
2019-10-12 14:48:19 +08:00
frame.origin.x = centerX - self.frame.size.width / 2;
2019-07-25 19:56:49 +08:00
[self setFrame:frame];
}
- (CGFloat)centerY {
2019-10-12 14:48:19 +08:00
return self.frame.origin.y + self.frame.size.height / 2;
2019-07-25 19:56:49 +08:00
}
- (void)setCenterY:(CGFloat)centerY {
CGRect frame = self.frame;
2019-10-12 14:48:19 +08:00
frame.origin.y = centerY - self.frame.size.height / 2;
2019-07-25 19:56:49 +08:00
[self setFrame:frame];
}
2019-07-25 21:03:31 +08:00
2019-07-25 19:56:49 +08:00
@end