如果是在IOS的应用方面,很多时候,是不需要我们去做一些封装的和添加一些比较好看,比较好看的UILabel显示。
游戏方面,就避免不了需要提高IOS完全没有的显示风格,这就需要提供炫的风格了。
但是,应用谁说的准就不用呢?
在发展到今天,开源的项目提供给我们很多的方便,在UILabel上面,就有开源的封装类。
这个其实类似于上一节的,IOS 应用/游戏项目应该如何灵活封装 控件显示样式与项目颜色的公用 http://blog.csdn.net/zhbitxhd/article/details/24296067
实际上,这个开源的项目就是为了完成同样的事情。所以,我们不需要再造车轮
这里提供链接以供使用,并且,我们的项目也在使用。
THLabel
https://github.com/MuscleRumble/THLabel
文章中,有详细的解释如何使用。这里我就不多说了。
Installation
Add CoreText.framework
to your Link Binary with Libraries list.
And drag these files into your project:
THLabel.h
THLabel.m
You can create THLabels programmatically, or create them in Interface Builder by dragging an ordinary UILabel into your view and setting its Custom Class to THLabel.
Properties
@property (nonatomic, assign) CGFloat shadowBlur;
Additionally to UILabel's shadowColor
and shadowOffset
, you can set a shadow blur to soften the shadow.
@property (nonatomic, assign) CGFloat innerShadowBlur;
@property (nonatomic, assign) CGSize innerShadowOffset;
@property (nonatomic, strong) UIColor *innerShadowColor;
The inner shadow has similar properties as UILabel's shadow, once again additionally with a shadow blur. If an inner shadow and a stroke are overlapping, it will appear beneath the stroke.
@property (nonatomic, assign) CGFloat strokeSize;
@property (nonatomic, strong) UIColor *strokeColor;
@property (nonatomic, assign) THLabelStrokePosition strokePosition;
You can set an outer, centered or inner stroke by setting the strokePosition
property. Default value isTHLabelStrokePositionOutside
. Other options are THLabelStrokePositionCenter
andTHLabelStrokePositionInside
.
@property (nonatomic, strong) UIColor *gradientStartColor;
@property (nonatomic, strong) UIColor *gradientEndColor;
@property (nonatomic, copy) NSArray *gradientColors;
The gradient can consist of multiple colors, which have to be saved as UIColor objects in the gradientColors
array. For more convenience, gradientStartColor
and gradientEndColor
will fill up the array accordingly.
@property (nonatomic, assign) CGPoint gradientStartPoint;
@property (nonatomic, assign) CGPoint gradientEndPoint;
The starting and ending points of the gradient are in the range 0 to 1, where (0, 0) is the top-left and (1, 1) the bottom-right of the text. The default value for gradientStartPoint
is (0.5, 0.2) and for gradientEndPoint
it is (0.5, 0.8).
@property (nonatomic, assign) THLabelFadeTruncatingMode fadeTruncatingMode;
You can fade in/out your label by setting the fadeTruncatingMode
property. Default value isTHLabelFadeTruncatingModeNone
. The options are THLabelFadeTruncatingModeTail
,THLabelFadeTruncatingModeHead
and THLabelFadeTruncatingModeHeadAndTail
.
@property (nonatomic, assign) UIEdgeInsets textInsets;
Effects like stroke and shadow can't be drawn outside of the bounds of the label view. For labels that are not center-aligned, you may need to set text insets to move a bit away from the edge.