Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onurersel/uiview-move
UIView category which changes frame values with single parameter rather than assigning CGRects
https://github.com/onurersel/uiview-move
Last synced: 16 days ago
JSON representation
UIView category which changes frame values with single parameter rather than assigning CGRects
- Host: GitHub
- URL: https://github.com/onurersel/uiview-move
- Owner: onurersel
- License: mit
- Created: 2015-07-01T09:01:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-13T05:40:38.000Z (almost 9 years ago)
- Last Synced: 2024-11-29T13:36:03.921Z (24 days ago)
- Language: Objective-C
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UIView-Move
### Purpose
It's too tidious to reassign unchanged frame values everytime you want to move your UIView, even though you only change a single parameter. UIView-Move supplies helper getter/setter methods for these situations.
### Installation
Copy UIView-Move.h and UIView-Move.m files to your project. Or use Cocoapods
pod 'UIView-Move'
### Usage
Import category to the class you want to use it in, or
```objc
#import "UIView+Move.h"
``````objc
//Creating a black square to test on
UIView *view = [UIView new];
view.backgroundColor = [UIColor blackColor];
view.frame = CGRectMake(0, 0, 100, 100);
[someView addSubview:view];//Moving our view around
view.x = 200;
view.y = 250;//Resizing
view.width = 150;
view.height = 150;
```You can position your view relative its parent's frame
```objc
//Following lines will position our rectangle at the center of it's super
view.left = view.superview.width/2.0 - view.width/2.0;
view.top = view.superview.height/2.0 - view.height/2.0;//This will snap the box to bottom right of superviews frame
view.right = 0;
view.bottom = 0;//Animates the box to the top left
[UIView animateWithDuration:1 animations:^{
view.top = 0;
view.x = 0;
}];
```Or you can position the view's center relative to center of it's parent frame
```objc
//Places view to middle of its parent
view.midX = 0;
view.midY = 0;
```