UILabel with image placed from left or right

Related tags

Label SMIconLabel
Overview

SMIconLabel

Version License Platform

UILabel with possibility to place small icon on the left or on the right side. Take a look at preview image or build sample app to see how it works.

Preview

Installation

Manually

This repo has an example project, but if you want to include SMIconLabel you need only one file SMIconLabel.swift.

CocoaPods

Alternatively you can use CocoaPods to install:

pod 'SMIconLabel'

Usage

Usage is as simple as possible. Here is an Swift 2.0 example:

let labelLeft = SMIconLabel(frame: CGRect(x: 10, y: 10, width: view.frame.size.width - 20, height: 20))
labelLeft.text = "Icon on the left, text on the left"

// Here is the magic
labelLeft.icon = UIImage(named: "Bell")    // Set icon image
labelLeft.iconPadding = 5                  // Set padding between icon and label
labelLeft.numberOfLines = 0                // Required
labelLeft.iconPosition = (.left, .top)   // Icon position
view.addSubview(labelLeft)

Icon Position

Icon position should be customized via iconPosition property. It's defined next way:

typealias SMIconLabel.Position = (horizontal: SMIconLabel.HorizontalPosition, vertical: SMIconLabel.VerticalPosition)

In this case if you want to make icon to be placed in top-left do:

labelLeft.iconPosition = (.left, .top)
You might also like...
MTLLinkLabel is linkable UILabel. Written in Swift.
MTLLinkLabel is linkable UILabel. Written in Swift.

# MTLLinkLabel is linkable UILabel. Written in Swift. Requirements iOS 8.0+ Xcode 7.3+ Installation Carthage You can install Carthage with Homebrew. $

Adds animated counting support to UILabel.
Adds animated counting support to UILabel.

UICountingLabel Adds animated counting support to UILabel. CocoaPods UICountingLabel is available on CocoaPods. Add this to your Podfile: pod 'UICount

A simple designable subclass on UILabel with extra IBDesignable and Blinking features.
A simple designable subclass on UILabel with extra IBDesignable and Blinking features.

JSLabel Demo pod try JSLabel ...or clone this repo and build and run/test the JSLabel project in Xcode to see JSLabel in action. If you don't have Coc

Lightweight library to set an Image as text background. Written in swift.
Lightweight library to set an Image as text background. Written in swift.

Simple and light weight UIView that animate text with an image.

Made in Swift - Tag layout for UICollectionView supporting 3 types of alignments - Left || Centre || Right
Made in Swift - Tag layout for UICollectionView supporting 3 types of alignments - Left || Centre || Right

TagCellLayout About Its an ui-collection-view LAYOUT class that takes care of all the logic behind making tags like layout using UICollectionView. It

A PageView Swiping to the left will go to previous page and swiping to the right will go to next page
A PageView Swiping to the left will go to previous page and swiping to the right will go to next page

PageView This package creates a PageView. Swiping to the left will go to previous page and swiping to the right will go to next page. You can find how

Made in Swift - Tag layout for UICollectionView supporting 3 types of alignments - Left || Centre || Right
Made in Swift - Tag layout for UICollectionView supporting 3 types of alignments - Left || Centre || Right

TagCellLayout About Its an ui-collection-view LAYOUT class that takes care of all the logic behind making tags like layout using UICollectionView. It

Alignment Control is a component to align top, middle, bottom, left, center, right.
Alignment Control is a component to align top, middle, bottom, left, center, right.

AlignmentControl is a component for alignment Direction AlignmentDirection Horizontal Vertical Mode AlignmentMode Left Center Right Top Middle Bottom

A paging menu controller built from other view controllers placed inside a scroll view (like Spotify, Windows Phone, Instagram)
A paging menu controller built from other view controllers placed inside a scroll view (like Spotify, Windows Phone, Instagram)

Unfortunately, life gets in the way sometimes and I won't be able to maintain this library any longer and upgrade this library to where it needs to be

UITextField with underline and left image
UITextField with underline and left image

TJTextField UITextField with underline and left image Version: 1.0 Features Add image in UITextField Left text pedding Underline whole UITextField Sho

SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.
SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.

SwiftySideMenu SwiftySideMenu is a lightweight, fully customizable, and easy to use controller to add left menu and center view controllers with scale

TomatoVerticalMenuMania lets you create a vertical, scrollable menu to the left of the screen.
TomatoVerticalMenuMania lets you create a vertical, scrollable menu to the left of the screen.

TomatoVerticalMenuMania Framework Development and compatibility Development platform: iOS Language: Swift Compatibility: iOS 13 or greater Description

Left Side Menu \ Side Bar with modern interface for iOS

SideMenu A customizable, interactive, auto expanding and collapsing side menu fo

C4 is an open-source creative coding framework that harnesses the power of native iOS programming with a simplified API that gets you working with media right away. Build artworks, design interfaces and explore new possibilities working with media and interaction. LifetimeTracker can surface retain cycle / memory issues right as you develop your application
LifetimeTracker can surface retain cycle / memory issues right as you develop your application

LifetimeTracker Bar style Circular style LifetimeTracker can surface retain cycle / memory issues right as you develop your application, and it will s

VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.
VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.

Features Variable PIN length Underline, border and custom styles The error status with / without shake animation Resetting the error status manually,

The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.
The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.

Color Game The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun. Getting Started Insta

🧭 SwiftUI navigation done right

🧭 NavigationKit NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Usi

The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.
The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.

Color Game The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun. Getting Started Insta

Comments
  • Swift 4 Conversion Issue

    Swift 4 Conversion Issue

    Getting NSFontAttributeName' has been renamed to 'NSAttributedStringKey.font' , error after converting to swift 4. My current version for SMIconLabel is 0.4.0. swift4_conversionissue

    opened by AniruddhaPol 1
  • There are some errors after converting it from swift 2.3 to swift 3.0

    There are some errors after converting it from swift 2.3 to swift 3.0

    Hello,

    I developed this pod when the iOS version 9.3 and I need it to upgrade into latest iOS version. But After converting SMIconLabel, there are many errors. Could you upgrade your repository works well for latest iOS version?

    Thanks

    opened by ilnurYalal 1
  • uitableviewcell

    uitableviewcell

    Hi

    When i use the label in cell the size gets changed and as a consequence the text doesn't fit anymore cell.itemLabel?.icon = UIImage(named: "hanger-icon") cell.itemLabel?.iconPadding = 5 cell.itemLabel?.numberOfLines = 0 cell.itemLabel?.iconPosition = (.left, .center )

    Why did I get wrong

    opened by raphaels17 0
  • Text not showing properly for icon position ( .Right, .Center )

    Text not showing properly for icon position ( .Right, .Center )

    labelLeft.icon = UIImage(named: "Bell") // Set icon image labelLeft.iconPadding = 5 // Set padding between icon and label labelLeft.numberOfLines = 1 // Required labelLeft.iconPosition =( .Right, .Center ) // Icon position

    In this case text is not shown properly. Fixed it by updating SMIconLabel as if iconPosition.horizontal == .Right { if textAlignment == .Right { iconView.frame = CGRectOffset(iconView.frame, frame.width - iconView.frame.width, iconYPosition) // newRect = CGRectMake(frame.width - size.width - iconView.frame.width - iconPadding, 0, size.width, height) newRect = CGRectMake(0, 0, frame.width - (iconView.frame.width + iconPadding), height) }

    opened by miraz029 0
Owner
Anatoliy Voropay
Swifter :]
Anatoliy Voropay
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Dec 26, 2022
Simple countdown UILabel with morphing animation, and some useful function.

CountdownLabel Simple countdown UILabel with morphing animation, and some useful function. features Simple creation Easily get status of countdown fro

keishi suzuki 903 Dec 29, 2022
Glitching UILabel for iOS 📺

Glitching UILabel for iOS ?? Created by Lee Sun-Hyoup. Try the sample $ pod try GlitchLabel Requirements iOS 8.0+ Swift 3 Xcode 8 Installation CocoaP

Lee Sun-Hyoup 1k Dec 14, 2022
Incrementable UILabel for iOS and tvOS

IncrementableLabel IncrementableLabel is the easiest way to have incrementable numbers in an UILabel! Usage let myIncrementableLabel = IncrementableLa

Tom Baranes 81 Feb 4, 2022
KDEDateLabel is an UILabel subclass that updates itself to make time ago's format easier.

KDEDateLabel KDEDateLabel is an UILabel subclass that saves you from refreshing it when using 'time ago' format. Installation You have multiple choice

Kevin Delannoy 117 May 16, 2022
A morphing UILabel subclass written in Swift.

LTMorphingLabel A morphing UILabel subclass written in Swift. The .Scale effect mimicked Apple's QuickType animation of iOS 8 of WWDC 2014. New morphi

Lex Tang 7.9k Jan 4, 2023
A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App.

MZTimerLabel Purpose MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple

Mines Chan 1.6k Dec 14, 2022
A drop-in replacement for UILabel that supports attributes, data detectors, links, and more

TTTAttributedLabel A drop-in replacement for UILabel that supports attributes, data detectors, links, and more TTTAttributedLabel is a drop-in replace

TTTAttributedLabel 8.8k Dec 30, 2022
UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.

THLabel THLabel is a subclass of UILabel, which additionally allows shadow blur, inner shadow, stroke text and fill gradient. Requirements iOS 4.0 or

Tobias Hagemann 654 Nov 27, 2022
UILabel replacement with fine-grain appear/disappear animation

ZCAnimatedLabel UILabel-like view with easy to extend appear/disappear animation Features Rich text support (with NSAttributedString) Group aniamtion

Chen 2.3k Dec 5, 2022