├── .gitignore ├── README.md ├── Screenshot └── YLLabel.png ├── YLLabelDemo.xcodeproj └── project.pbxproj └── YLLabelDemo ├── .DS_Store ├── Default-568h@2x.png ├── Default.png ├── Default@2x.png ├── YLAppDelegate.h ├── YLAppDelegate.m ├── YLLabel ├── YLLabel.h └── YLLabel.m ├── YLLabelDemo-Info.plist ├── YLLabelDemo-Prefix.pch ├── YLViewController.h ├── YLViewController.m ├── en.lproj ├── InfoPlist.strings └── YLViewController_iPhone.xib └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | build/* 3 | *.pbxuser 4 | !default.pbxuser 5 | *.mode1v3 6 | !default.mode1v3 7 | *.mode2v3 8 | !default.mode2v3 9 | *.perspectivev3 10 | !default.perspectivev3 11 | *.xcworkspace 12 | !default.xcworkspace 13 | xcuserdata 14 | profile 15 | *.moved-aside 16 | .DS_Store 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | YLLabel 2 | ======= 3 | **A simple justifier label for iOS** 4 | 5 | ## Screenshot 6 | [![](https://github.com/yuanlizbyy/YLLabel/blob/master/Screenshot/YLLabel.png?raw=true)](https://github.com/yuanlizbyy/YLLabel/blob/master/Screenshot/YLLabel.png?raw=true) 7 | 8 | ## Example Usage 9 | 10 | ```objective-c 11 | // YLLabel 12 | [justifyLabel setText:msg]; 13 | justifyLabel.textColor = [UIColor darkGrayColor]; 14 | justifyLabel.font = [UIFont systemFontOfSize:16.0f]; 15 | ``` 16 | 17 | 18 | ## Contact 19 | 20 | Eric Yuan 21 | - http://github.com/yuanlizbyy 22 | - http://weibo.com/yuanlizbyy 23 | - http://yuan.li 24 | - yuanlizbyy@gmail.com 25 | 26 | ## License 27 | 28 | YLLabel is available under the MIT license. 29 | 30 | -------------------------------------------------------------------------------- /Screenshot/YLLabel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanlizbyy/YLLabel/7bd02564ccee6f39f167097a7344bd4e95be29ff/Screenshot/YLLabel.png -------------------------------------------------------------------------------- /YLLabelDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0485EC6B164B8C9B00626805 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0485EC6A164B8C9B00626805 /* UIKit.framework */; }; 11 | 0485EC6D164B8C9B00626805 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0485EC6C164B8C9B00626805 /* Foundation.framework */; }; 12 | 0485EC6F164B8C9B00626805 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0485EC6E164B8C9B00626805 /* CoreGraphics.framework */; }; 13 | 0485EC75164B8C9B00626805 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0485EC73164B8C9B00626805 /* InfoPlist.strings */; }; 14 | 0485EC77164B8C9B00626805 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0485EC76164B8C9B00626805 /* main.m */; }; 15 | 0485EC7B164B8C9B00626805 /* YLAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0485EC7A164B8C9B00626805 /* YLAppDelegate.m */; }; 16 | 0485EC7D164B8C9B00626805 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 0485EC7C164B8C9B00626805 /* Default.png */; }; 17 | 0485EC7F164B8C9B00626805 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0485EC7E164B8C9B00626805 /* Default@2x.png */; }; 18 | 0485EC81164B8C9B00626805 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0485EC80164B8C9B00626805 /* Default-568h@2x.png */; }; 19 | 0485EC84164B8C9B00626805 /* YLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0485EC83164B8C9B00626805 /* YLViewController.m */; }; 20 | 0485EC87164B8C9B00626805 /* YLViewController_iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0485EC85164B8C9B00626805 /* YLViewController_iPhone.xib */; }; 21 | 0485EC93164B8CD100626805 /* YLLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 0485EC92164B8CD100626805 /* YLLabel.m */; }; 22 | 0485EC95164B957600626805 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0485EC94164B957600626805 /* CoreText.framework */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 0485EC66164B8C9B00626805 /* YLLabelDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YLLabelDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 0485EC6A164B8C9B00626805 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 28 | 0485EC6C164B8C9B00626805 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 29 | 0485EC6E164B8C9B00626805 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 30 | 0485EC72164B8C9B00626805 /* YLLabelDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "YLLabelDemo-Info.plist"; sourceTree = ""; }; 31 | 0485EC74164B8C9B00626805 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 32 | 0485EC76164B8C9B00626805 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 33 | 0485EC78164B8C9B00626805 /* YLLabelDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "YLLabelDemo-Prefix.pch"; sourceTree = ""; }; 34 | 0485EC79164B8C9B00626805 /* YLAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YLAppDelegate.h; sourceTree = ""; }; 35 | 0485EC7A164B8C9B00626805 /* YLAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YLAppDelegate.m; sourceTree = ""; }; 36 | 0485EC7C164B8C9B00626805 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 37 | 0485EC7E164B8C9B00626805 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; 38 | 0485EC80164B8C9B00626805 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 39 | 0485EC82164B8C9B00626805 /* YLViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YLViewController.h; sourceTree = ""; }; 40 | 0485EC83164B8C9B00626805 /* YLViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YLViewController.m; sourceTree = ""; }; 41 | 0485EC86164B8C9B00626805 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/YLViewController_iPhone.xib; sourceTree = ""; }; 42 | 0485EC91164B8CD100626805 /* YLLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = YLLabel.h; path = YLLabel/YLLabel.h; sourceTree = ""; }; 43 | 0485EC92164B8CD100626805 /* YLLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = YLLabel.m; path = YLLabel/YLLabel.m; sourceTree = ""; }; 44 | 0485EC94164B957600626805 /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 0485EC63164B8C9B00626805 /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | 0485EC95164B957600626805 /* CoreText.framework in Frameworks */, 53 | 0485EC6B164B8C9B00626805 /* UIKit.framework in Frameworks */, 54 | 0485EC6D164B8C9B00626805 /* Foundation.framework in Frameworks */, 55 | 0485EC6F164B8C9B00626805 /* CoreGraphics.framework in Frameworks */, 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 0485EC5B164B8C9B00626805 = { 63 | isa = PBXGroup; 64 | children = ( 65 | 0485EC70164B8C9B00626805 /* YLLabelDemo */, 66 | 0485EC69164B8C9B00626805 /* Frameworks */, 67 | 0485EC67164B8C9B00626805 /* Products */, 68 | ); 69 | sourceTree = ""; 70 | }; 71 | 0485EC67164B8C9B00626805 /* Products */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 0485EC66164B8C9B00626805 /* YLLabelDemo.app */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 0485EC69164B8C9B00626805 /* Frameworks */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 0485EC94164B957600626805 /* CoreText.framework */, 83 | 0485EC6A164B8C9B00626805 /* UIKit.framework */, 84 | 0485EC6C164B8C9B00626805 /* Foundation.framework */, 85 | 0485EC6E164B8C9B00626805 /* CoreGraphics.framework */, 86 | ); 87 | name = Frameworks; 88 | sourceTree = ""; 89 | }; 90 | 0485EC70164B8C9B00626805 /* YLLabelDemo */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 0485EC90164B8CA600626805 /* YLLabel */, 94 | 0485EC79164B8C9B00626805 /* YLAppDelegate.h */, 95 | 0485EC7A164B8C9B00626805 /* YLAppDelegate.m */, 96 | 0485EC82164B8C9B00626805 /* YLViewController.h */, 97 | 0485EC83164B8C9B00626805 /* YLViewController.m */, 98 | 0485EC85164B8C9B00626805 /* YLViewController_iPhone.xib */, 99 | 0485EC71164B8C9B00626805 /* Supporting Files */, 100 | ); 101 | path = YLLabelDemo; 102 | sourceTree = ""; 103 | }; 104 | 0485EC71164B8C9B00626805 /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 0485EC72164B8C9B00626805 /* YLLabelDemo-Info.plist */, 108 | 0485EC73164B8C9B00626805 /* InfoPlist.strings */, 109 | 0485EC76164B8C9B00626805 /* main.m */, 110 | 0485EC78164B8C9B00626805 /* YLLabelDemo-Prefix.pch */, 111 | 0485EC7C164B8C9B00626805 /* Default.png */, 112 | 0485EC7E164B8C9B00626805 /* Default@2x.png */, 113 | 0485EC80164B8C9B00626805 /* Default-568h@2x.png */, 114 | ); 115 | name = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | 0485EC90164B8CA600626805 /* YLLabel */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 0485EC91164B8CD100626805 /* YLLabel.h */, 122 | 0485EC92164B8CD100626805 /* YLLabel.m */, 123 | ); 124 | name = YLLabel; 125 | sourceTree = ""; 126 | }; 127 | /* End PBXGroup section */ 128 | 129 | /* Begin PBXNativeTarget section */ 130 | 0485EC65164B8C9B00626805 /* YLLabelDemo */ = { 131 | isa = PBXNativeTarget; 132 | buildConfigurationList = 0485EC8D164B8C9B00626805 /* Build configuration list for PBXNativeTarget "YLLabelDemo" */; 133 | buildPhases = ( 134 | 0485EC62164B8C9B00626805 /* Sources */, 135 | 0485EC63164B8C9B00626805 /* Frameworks */, 136 | 0485EC64164B8C9B00626805 /* Resources */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | ); 142 | name = YLLabelDemo; 143 | productName = YLLabelDemo; 144 | productReference = 0485EC66164B8C9B00626805 /* YLLabelDemo.app */; 145 | productType = "com.apple.product-type.application"; 146 | }; 147 | /* End PBXNativeTarget section */ 148 | 149 | /* Begin PBXProject section */ 150 | 0485EC5D164B8C9B00626805 /* Project object */ = { 151 | isa = PBXProject; 152 | attributes = { 153 | CLASSPREFIX = YL; 154 | LastUpgradeCheck = 0450; 155 | ORGANIZATIONNAME = YuanLi; 156 | }; 157 | buildConfigurationList = 0485EC60164B8C9B00626805 /* Build configuration list for PBXProject "YLLabelDemo" */; 158 | compatibilityVersion = "Xcode 3.2"; 159 | developmentRegion = English; 160 | hasScannedForEncodings = 0; 161 | knownRegions = ( 162 | en, 163 | ); 164 | mainGroup = 0485EC5B164B8C9B00626805; 165 | productRefGroup = 0485EC67164B8C9B00626805 /* Products */; 166 | projectDirPath = ""; 167 | projectRoot = ""; 168 | targets = ( 169 | 0485EC65164B8C9B00626805 /* YLLabelDemo */, 170 | ); 171 | }; 172 | /* End PBXProject section */ 173 | 174 | /* Begin PBXResourcesBuildPhase section */ 175 | 0485EC64164B8C9B00626805 /* Resources */ = { 176 | isa = PBXResourcesBuildPhase; 177 | buildActionMask = 2147483647; 178 | files = ( 179 | 0485EC75164B8C9B00626805 /* InfoPlist.strings in Resources */, 180 | 0485EC7D164B8C9B00626805 /* Default.png in Resources */, 181 | 0485EC7F164B8C9B00626805 /* Default@2x.png in Resources */, 182 | 0485EC81164B8C9B00626805 /* Default-568h@2x.png in Resources */, 183 | 0485EC87164B8C9B00626805 /* YLViewController_iPhone.xib in Resources */, 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | }; 187 | /* End PBXResourcesBuildPhase section */ 188 | 189 | /* Begin PBXSourcesBuildPhase section */ 190 | 0485EC62164B8C9B00626805 /* Sources */ = { 191 | isa = PBXSourcesBuildPhase; 192 | buildActionMask = 2147483647; 193 | files = ( 194 | 0485EC77164B8C9B00626805 /* main.m in Sources */, 195 | 0485EC7B164B8C9B00626805 /* YLAppDelegate.m in Sources */, 196 | 0485EC84164B8C9B00626805 /* YLViewController.m in Sources */, 197 | 0485EC93164B8CD100626805 /* YLLabel.m in Sources */, 198 | ); 199 | runOnlyForDeploymentPostprocessing = 0; 200 | }; 201 | /* End PBXSourcesBuildPhase section */ 202 | 203 | /* Begin PBXVariantGroup section */ 204 | 0485EC73164B8C9B00626805 /* InfoPlist.strings */ = { 205 | isa = PBXVariantGroup; 206 | children = ( 207 | 0485EC74164B8C9B00626805 /* en */, 208 | ); 209 | name = InfoPlist.strings; 210 | sourceTree = ""; 211 | }; 212 | 0485EC85164B8C9B00626805 /* YLViewController_iPhone.xib */ = { 213 | isa = PBXVariantGroup; 214 | children = ( 215 | 0485EC86164B8C9B00626805 /* en */, 216 | ); 217 | name = YLViewController_iPhone.xib; 218 | sourceTree = ""; 219 | }; 220 | /* End PBXVariantGroup section */ 221 | 222 | /* Begin XCBuildConfiguration section */ 223 | 0485EC8B164B8C9B00626805 /* Debug */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_OBJC_ARC = YES; 230 | CLANG_WARN_EMPTY_BODY = YES; 231 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 232 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Yuen Lee (9258Z5FE33)"; 233 | COPY_PHASE_STRIP = NO; 234 | GCC_C_LANGUAGE_STANDARD = gnu99; 235 | GCC_DYNAMIC_NO_PIC = NO; 236 | GCC_OPTIMIZATION_LEVEL = 0; 237 | GCC_PREPROCESSOR_DEFINITIONS = ( 238 | "DEBUG=1", 239 | "$(inherited)", 240 | ); 241 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 243 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 244 | GCC_WARN_UNUSED_VARIABLE = YES; 245 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 246 | ONLY_ACTIVE_ARCH = YES; 247 | "PROVISIONING_PROFILE[sdk=iphoneos*]" = "F016324B-D0E4-4E97-BA46-FDFA8D63253E"; 248 | SDKROOT = iphoneos; 249 | TARGETED_DEVICE_FAMILY = "1,2"; 250 | }; 251 | name = Debug; 252 | }; 253 | 0485EC8C164B8C9B00626805 /* Release */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | ALWAYS_SEARCH_USER_PATHS = NO; 257 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 258 | CLANG_CXX_LIBRARY = "libc++"; 259 | CLANG_ENABLE_OBJC_ARC = YES; 260 | CLANG_WARN_EMPTY_BODY = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | CODE_SIGN_IDENTITY = "iPhone Developer: Yuen Lee (9258Z5FE33)"; 263 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 264 | COPY_PHASE_STRIP = YES; 265 | GCC_C_LANGUAGE_STANDARD = gnu99; 266 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 267 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 270 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 271 | PROVISIONING_PROFILE = "927E120F-5149-4C19-BD57-0B3C40E6E8F3"; 272 | SDKROOT = iphoneos; 273 | TARGETED_DEVICE_FAMILY = "1,2"; 274 | VALIDATE_PRODUCT = YES; 275 | }; 276 | name = Release; 277 | }; 278 | 0485EC8E164B8C9B00626805 /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 282 | GCC_PREFIX_HEADER = "YLLabelDemo/YLLabelDemo-Prefix.pch"; 283 | INFOPLIST_FILE = "YLLabelDemo/YLLabelDemo-Info.plist"; 284 | PRODUCT_NAME = "$(TARGET_NAME)"; 285 | WRAPPER_EXTENSION = app; 286 | }; 287 | name = Debug; 288 | }; 289 | 0485EC8F164B8C9B00626805 /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 293 | GCC_PREFIX_HEADER = "YLLabelDemo/YLLabelDemo-Prefix.pch"; 294 | INFOPLIST_FILE = "YLLabelDemo/YLLabelDemo-Info.plist"; 295 | PRODUCT_NAME = "$(TARGET_NAME)"; 296 | WRAPPER_EXTENSION = app; 297 | }; 298 | name = Release; 299 | }; 300 | /* End XCBuildConfiguration section */ 301 | 302 | /* Begin XCConfigurationList section */ 303 | 0485EC60164B8C9B00626805 /* Build configuration list for PBXProject "YLLabelDemo" */ = { 304 | isa = XCConfigurationList; 305 | buildConfigurations = ( 306 | 0485EC8B164B8C9B00626805 /* Debug */, 307 | 0485EC8C164B8C9B00626805 /* Release */, 308 | ); 309 | defaultConfigurationIsVisible = 0; 310 | defaultConfigurationName = Release; 311 | }; 312 | 0485EC8D164B8C9B00626805 /* Build configuration list for PBXNativeTarget "YLLabelDemo" */ = { 313 | isa = XCConfigurationList; 314 | buildConfigurations = ( 315 | 0485EC8E164B8C9B00626805 /* Debug */, 316 | 0485EC8F164B8C9B00626805 /* Release */, 317 | ); 318 | defaultConfigurationIsVisible = 0; 319 | defaultConfigurationName = Release; 320 | }; 321 | /* End XCConfigurationList section */ 322 | }; 323 | rootObject = 0485EC5D164B8C9B00626805 /* Project object */; 324 | } 325 | -------------------------------------------------------------------------------- /YLLabelDemo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanlizbyy/YLLabel/7bd02564ccee6f39f167097a7344bd4e95be29ff/YLLabelDemo/.DS_Store -------------------------------------------------------------------------------- /YLLabelDemo/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanlizbyy/YLLabel/7bd02564ccee6f39f167097a7344bd4e95be29ff/YLLabelDemo/Default-568h@2x.png -------------------------------------------------------------------------------- /YLLabelDemo/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanlizbyy/YLLabel/7bd02564ccee6f39f167097a7344bd4e95be29ff/YLLabelDemo/Default.png -------------------------------------------------------------------------------- /YLLabelDemo/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanlizbyy/YLLabel/7bd02564ccee6f39f167097a7344bd4e95be29ff/YLLabelDemo/Default@2x.png -------------------------------------------------------------------------------- /YLLabelDemo/YLAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // YLAppDelegate.h 3 | // YLLabelDemo 4 | // 5 | // Created by Eric Yuan on 12-11-8. 6 | // Copyright (c) 2012年 YuanLi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class YLViewController; 12 | 13 | @interface YLAppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @property (strong, nonatomic) YLViewController *viewController; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /YLLabelDemo/YLAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // YLAppDelegate.m 3 | // YLLabelDemo 4 | // 5 | // Created by Eric Yuan on 12-11-8. 6 | // Copyright (c) 2012年 YuanLi. All rights reserved. 7 | // 8 | 9 | #import "YLAppDelegate.h" 10 | 11 | #import "YLViewController.h" 12 | 13 | @implementation YLAppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 18 | // Override point for customization after application launch. 19 | self.viewController = [[YLViewController alloc] initWithNibName:@"YLViewController_iPhone" bundle:nil]; 20 | self.window.rootViewController = self.viewController; 21 | [self.window makeKeyAndVisible]; 22 | return YES; 23 | } 24 | 25 | - (void)applicationWillResignActive:(UIApplication *)application 26 | { 27 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 28 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 29 | } 30 | 31 | - (void)applicationDidEnterBackground:(UIApplication *)application 32 | { 33 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application 38 | { 39 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 40 | } 41 | 42 | - (void)applicationDidBecomeActive:(UIApplication *)application 43 | { 44 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 45 | } 46 | 47 | - (void)applicationWillTerminate:(UIApplication *)application 48 | { 49 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /YLLabelDemo/YLLabel/YLLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // YLLabel.h 3 | // YLLabelDemo 4 | // 5 | // Created by Eric Yuan on 12-11-8. 6 | // Copyright (c) 2012年 YuanLi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YLLabel : UIView 12 | { 13 | NSMutableAttributedString* _string; 14 | UIFont* _font; 15 | UIColor* _textColor; 16 | } 17 | 18 | @property (nonatomic, strong)NSMutableAttributedString* string; 19 | @property (nonatomic, strong)UIFont* font; 20 | @property (nonatomic, strong)UIColor* textColor; 21 | 22 | - (void)setText:(NSString*)text; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /YLLabelDemo/YLLabel/YLLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // YLLabel.m 3 | // YLLabelDemo 4 | // 5 | // Created by Eric Yuan on 12-11-8. 6 | // Copyright (c) 2012年 YuanLi. All rights reserved. 7 | // 8 | 9 | #import "YLLabel.h" 10 | #import 11 | 12 | @interface YLLabel(Private) 13 | 14 | - (void)formatString; 15 | 16 | @end 17 | 18 | @implementation YLLabel 19 | 20 | @synthesize font = _font; 21 | @synthesize textColor = _textColor; 22 | 23 | - (id)initWithFrame:(CGRect)frame 24 | { 25 | self = [super initWithFrame:frame]; 26 | if (self) { 27 | self.backgroundColor = [UIColor clearColor]; 28 | } 29 | return self; 30 | } 31 | 32 | - (void)drawRect:(CGRect)rect 33 | { 34 | [self formatString]; 35 | 36 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 37 | CGContextSetTextMatrix(ctx, CGAffineTransformIdentity); 38 | 39 | CGContextTranslateCTM(ctx,0, self.bounds.size.height); 40 | CGContextScaleCTM(ctx, 1.0, -1.0); 41 | 42 | CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)_string); 43 | 44 | CGRect bounds = self.bounds; 45 | bounds.origin.x = bounds.origin.x + 8; 46 | bounds.size.width = bounds.size.width - 16; 47 | 48 | CGMutablePathRef path = CGPathCreateMutable(); 49 | CGPathAddRect(path, NULL, bounds); 50 | 51 | CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, [_string length]), path, NULL); 52 | CFRelease(path); 53 | 54 | CTFrameDraw(frame, ctx); 55 | CFRelease(frame); 56 | CFRelease(frameSetter); 57 | } 58 | 59 | - (void)setText:(NSString *)text 60 | { 61 | _string = [[NSMutableAttributedString alloc] initWithString:text]; 62 | [self setNeedsDisplay]; 63 | } 64 | 65 | - (void)setTextColor:(UIColor *)textColor 66 | { 67 | _textColor = textColor; 68 | } 69 | 70 | - (void)formatString 71 | { 72 | CTTextAlignment alignment = kCTJustifiedTextAlignment; 73 | 74 | CGFloat paragraphSpacing = 11.0; 75 | CGFloat paragraphSpacingBefore = 0.0; 76 | CGFloat firstLineHeadIndent = 0.0; 77 | CGFloat headIndent = 0.0; 78 | 79 | CTParagraphStyleSetting settings[] = 80 | { 81 | {kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment}, 82 | {kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(CGFloat), &firstLineHeadIndent}, 83 | {kCTParagraphStyleSpecifierHeadIndent, sizeof(CGFloat), &headIndent}, 84 | {kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), ¶graphSpacing}, 85 | {kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), ¶graphSpacingBefore}, 86 | }; 87 | 88 | CTParagraphStyleRef style; 89 | style = CTParagraphStyleCreate(settings, sizeof(settings)/sizeof(CTParagraphStyleSetting)); 90 | 91 | if (NULL == style) { 92 | // error... 93 | return; 94 | } 95 | 96 | [_string addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:(__bridge NSObject*)style, (NSString*)kCTParagraphStyleAttributeName, nil] 97 | range:NSMakeRange(0, [_string length])]; 98 | 99 | CFRelease(style); 100 | 101 | if (nil == _font) { 102 | _font = [UIFont boldSystemFontOfSize:12.0]; 103 | } 104 | 105 | CTFontRef fontRef = CTFontCreateWithName((__bridge CFStringRef)_font.fontName, _font.pointSize, NULL); 106 | [_string addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:(__bridge NSObject*)fontRef, (NSString*)kCTFontAttributeName, nil] 107 | range:NSMakeRange(0, [_string length])]; 108 | 109 | CGColorRef colorRef = _textColor.CGColor; 110 | [_string addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:(__bridge NSObject*)colorRef,(NSString*)kCTForegroundColorAttributeName, nil] 111 | range:NSMakeRange(0, [_string length])]; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /YLLabelDemo/YLLabelDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | li.yuan.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /YLLabelDemo/YLLabelDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'YLLabelDemo' target in the 'YLLabelDemo' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /YLLabelDemo/YLViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // YLViewController.h 3 | // YLLabelDemo 4 | // 5 | // Created by Eric Yuan on 12-11-8. 6 | // Copyright (c) 2012年 YuanLi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class YLLabel; 12 | 13 | @interface YLViewController : UIViewController { 14 | IBOutlet YLLabel* justifyLabel; 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /YLLabelDemo/YLViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // YLViewController.m 3 | // YLLabelDemo 4 | // 5 | // Created by Eric Yuan on 12-11-8. 6 | // Copyright (c) 2012年 YuanLi. All rights reserved. 7 | // 8 | 9 | #import "YLViewController.h" 10 | #import "YLLabel.h" 11 | 12 | NSString* const msg = @"壬戌之秋,七月既望,苏子与客泛舟游于赤壁之下。清风《赤壁赋》文徵明书徐来,水波不兴。举酒属(zhǔ)客,诵明月之诗,歌窈窕之章。少(shǎo) 焉,月出于东山之上,徘徊于斗(dǒu)牛之间。白露横江,水光接天。纵一苇之所如,凌万顷之茫然。浩浩乎如冯 (píng) 虚御风,而不知其所止;飘飘乎如遗世独立,羽化而登仙。"; 13 | 14 | @interface YLViewController () 15 | 16 | @end 17 | 18 | @implementation YLViewController 19 | 20 | - (void)viewDidLoad 21 | { 22 | [super viewDidLoad]; 23 | // Do any additional setup after loading the view, typically from a nib. 24 | 25 | // YLLabel 26 | [justifyLabel setText:msg]; 27 | justifyLabel.textColor = [UIColor darkGrayColor]; 28 | justifyLabel.font = [UIFont systemFontOfSize:16.0f]; 29 | } 30 | 31 | - (void)didReceiveMemoryWarning 32 | { 33 | [super didReceiveMemoryWarning]; 34 | // Dispose of any resources that can be recreated. 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /YLLabelDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /YLLabelDemo/en.lproj/YLViewController_iPhone.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1536 5 | 11G63 6 | 2843 7 | 1138.51 8 | 569.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 1929 12 | 13 | 14 | IBProxyObject 15 | IBUILabel 16 | IBUIView 17 | 18 | 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | PluginDependencyRecalculationVersion 23 | 24 | 25 | 26 | 27 | IBFilesOwner 28 | IBCocoaTouchFramework 29 | 30 | 31 | IBFirstResponder 32 | IBCocoaTouchFramework 33 | 34 | 35 | 36 | 274 37 | 38 | 39 | 40 | 292 41 | {{20, 66}, {280, 181}} 42 | 43 | 44 | 45 | _NS:9 46 | 47 | 3 48 | MQA 49 | 50 | 2 51 | 52 | 53 | IBCocoaTouchFramework 54 | 55 | 56 | 57 | 292 58 | {{125, 267}, {175, 21}} 59 | 60 | 61 | _NS:9 62 | NO 63 | YES 64 | 7 65 | NO 66 | IBCocoaTouchFramework 67 | ——(宋)苏轼 《赤壁赋》 68 | 69 | 3 70 | MC4zMzMzMzMzMzMzAA 71 | 72 | 73 | 0 74 | 2 75 | 76 | 2 77 | 14 78 | 79 | 80 | Helvetica-Bold 81 | 14 82 | 16 83 | 84 | NO 85 | 86 | 87 | {{0, 20}, {320, 548}} 88 | 89 | 90 | 91 | 92 | 3 93 | MQA 94 | 95 | 96 | NO 97 | 98 | 99 | IBUIScreenMetrics 100 | 101 | YES 102 | 103 | 104 | 105 | 106 | 107 | {320, 568} 108 | {568, 320} 109 | 110 | 111 | IBCocoaTouchFramework 112 | Retina 4 Full Screen 113 | 2 114 | 115 | IBCocoaTouchFramework 116 | 117 | 118 | 119 | 120 | 121 | 122 | view 123 | 124 | 125 | 126 | 7 127 | 128 | 129 | 130 | justifyLabel 131 | 132 | 133 | 134 | 26 135 | 136 | 137 | 138 | 139 | 140 | 0 141 | 142 | 143 | 144 | 145 | 146 | -1 147 | 148 | 149 | File's Owner 150 | 151 | 152 | -2 153 | 154 | 155 | 156 | 157 | 6 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 25 167 | 168 | 169 | 170 | 171 | 28 172 | 173 | 174 | 175 | 176 | 177 | 178 | YLViewController 179 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 180 | UIResponder 181 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 182 | YLLabel 183 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 184 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 185 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 186 | 187 | 188 | 189 | 190 | 191 | 28 192 | 193 | 194 | 195 | 196 | YLLabel 197 | UIView 198 | 199 | IBProjectSource 200 | ./Classes/YLLabel.h 201 | 202 | 203 | 204 | YLViewController 205 | UIViewController 206 | 207 | justifyLabel 208 | YLLabel 209 | 210 | 211 | justifyLabel 212 | 213 | justifyLabel 214 | YLLabel 215 | 216 | 217 | 218 | IBProjectSource 219 | ./Classes/YLViewController.h 220 | 221 | 222 | 223 | 224 | 0 225 | IBCocoaTouchFramework 226 | YES 227 | 3 228 | 1929 229 | 230 | 231 | -------------------------------------------------------------------------------- /YLLabelDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // YLLabelDemo 4 | // 5 | // Created by Eric Yuan on 12-11-8. 6 | // Copyright (c) 2012年 YuanLi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "YLAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([YLAppDelegate class])); 17 | } 18 | } 19 | --------------------------------------------------------------------------------