Latest 0.8.0
Homepage https://github.com/Patreon/PTRManualLayout
License Apache 2.0
Platforms ios 7.1
Authors ,

CI Status
Version
License
Platform

Layout your UIs in code. No tricks, no funny business, just dead simple layout.

Table of Contents

  1. Usage
  2. Example
  3. Installation
  4. Author
  5. License
  6. Contributing

Usage

  1. #import <PTRManualLayout/PTRManualLayout.h>
  2. Build your layout, typically in layoutSubviews, by mapping your views to PTRMLRects (see Example below)
  3. [layout apply] to make all your dreams come true

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

#import "ExampleView.h"
#import <PTRManualLayout/PTRManualLayout.h>

@interface ExampleView ()
@property (nonatomic, strong) UILabel *prompt;
@property (nonatomic, strong) UIButton *button;
@end

@implementation ExampleView

- (instancetype)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    self.prompt = [[UILabel alloc] initWithFrame:CGRectZero];
    self.prompt.text = @"PTRManualLayout lets you lay out your views with ease";
    [self addSubview:self.prompt];

    self.button = [[UIButton alloc] initWithFrame:CGRectZero];
    [self.button setTitle:@"Learn More"
                 forState:UIControlStateNormal];
    [self addSubview:self.button];
  }
  return self;
}

- (void)layoutSubviews {
  [super layoutSubviews];
  [[self buildLayout:self.bounds.size] apply];
}

- (CGSize)sizeThatFits:(CGSize)size {
  return [[self buildLayout:size] containingRect].size;
}

- (PTRMLLayout *)buildLayout:(CGSize)size {
  PTRMLLayout *layout = [MLLayout layoutWithBounds:(CGRect){CGPointZero, size}];

  CGFloat padding = 10;
  PTRMLLayout *insetRect = [PTRMLLayout rectWithCGRect:CGRectInset(layout.bounds.frame, padding, padding)];

  layout[self.prompt].size = [self.prompt sizeThatFits:insetRect.size];
  layout[self.prompt].centerX = insetRect.centerX;

  layout[self.button].size = [self.button sizeThatFits:insetRect.size];
  layout[self.button].centerX = insetRect.centerX;

  CGFloat totalHeightWithPadding = layout[self.prompt].height + padding + layout[self.button].height;
  layout[self.prompt].top = insetRect.centerY - (totalHeightWithPadding / 2);
  layout[self.button].bottom = insetRect.centerY + (totalHeightWithPadding / 2);

  return layout;
}

@end

Installation

PTRManualLayout is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "PTRManualLayout"

Author

Sam Morrison, [email protected]
David Kettler, [email protected]

License

PTRManualLayout is available under the Apache 2.0 license. See the LICENSE file for more info.

Contributing

  1. git clone [email protected]:Patreon/PTRManualLayout.git
  2. cd PTRManualLayout
  3. git checkout -b my-meaningful-improvements
  4. Write beautiful code that improves the project, creating or modifying tests to prove correctness.
  5. Commit said code and tests in a well-organized way.
  6. Confirm tests pass by opening Example/PTRRLMManualLayout.xcworkspace and running tests with Cmd+U (you may need to cd Example && pod install first)
  7. git push origin my-meaningful-improvements
  8. Open a pull request (hub pull-request, if you have hub)
  9. Have a chill discussion with the community about how to best integrate your improvements into mainline deployments

Latest podspec

{
    "name": "PTRManualLayout",
    "version": "0.8.0",
    "summary": "Easily layout your UIs in code",
    "description": "PTRManualLayout provides a set of utilities to easily lay out your views in code",
    "homepage": "https://github.com/Patreon/PTRManualLayout",
    "license": {
        "type": "Apache 2.0",
        "file": "LICENSE"
    },
    "authors": {
        "Sam Morrison": "[email protected]",
        "David Kettler": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Patreon/PTRManualLayout.git",
        "tag": "0.8.0"
    },
    "platforms": {
        "ios": "7.1"
    },
    "source_files": "PTRManualLayout/Classes/**/*"
}

Pin It on Pinterest

Share This