Coder Social home page Coder Social logo

mdabbagh88 / uiview-borders Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aaronn/uiview-borders

0.0 0.0 0.0 123 KB

Easy one-sided and offset borders on all UIViews.

License: BSD 2-Clause "Simplified" License

Objective-C 95.22% Ruby 4.78%

uiview-borders's Introduction

UIView+Borders

Updated For Swift 3

Add borders to everything! A quick and simple UIView category to add one-sided borders to your UIViews. Supports both layer-backed borders and UIView backed borders, if layers aren't possible. Supports one-sided borders with offset amounts for top, right, bottom and left sides!

Installation

Just add "UIView+Borders.h" and "UIView+Borders.m" to your project.

Usage

Import "UIView+Borders.h" and call any of the following on your UIView, specifying the thickness and color to get a CALayer backed border which you can then set into a property and add as a sublayer (or subview). There are also UIView-backed versions: check out UIView+Borders.h.

// Top
-(CALayer*)createTopBorderWithHeight: (CGFloat)height andColor:(UIColor*)color;
-(CALayer*)createTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset;

// Right
-(CALayer*)createRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(CALayer*)createRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;

// Bottom
-(CALayer*)createBottomBorderWithHeight: (CGFloat)height andColor:(UIColor*)color;
-(CALayer*)createBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset;

// Left
-(CALayer*)createLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(CALayer*)createLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;

Alternatively, if you just want a quick border dropped into your UIView, use these methods which just add a border to the current view:

// Top Border
-(void)addTopBorderWithHeight:(CGFloat)height andColor:(UIColor*)color;
-(void)addViewBackedTopBorderWithHeight:(CGFloat)height andColor:(UIColor*)color

// Right Border
-(void)addRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color
-(void)addViewBackedRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color

// Bottom Border
-(void)addBottomBorderWithHeight:(CGFloat)height andColor:(UIColor*)color
-(void)addViewBackedBottomBorderWithHeight:(CGFloat)height andColor:(UIColor*)color

// Left Border
-(void)addLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color
-(void)addViewBackedLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color

Why One Sided Borders?

One sided borders are an awesome tool for highlighting, recessing or separating various UI elements. For example, a light top-border with a dark bottom-border can be used to make something appear raised while a dark top-border makes the element look recessed. It's also handy for visually separating two views next to each other-- using a traditional layer border means doubling up on the width where the two views meet.

uiview-borders's People

Contributors

aaronn avatar nap-sam-dean avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.