如果是在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.