[无限互联]ios开发之FTCoreText的使用(2)

2019-03-28 22:09

102.

if (alignment != kCTCenterTextAlignment) frame.origin.x = (a

lignment == kCTLeftTextAlignment)? insets.left : (self.frame.size.width - img.size.width - insets.right);

103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119.

frame.origin.y += insets.top;

frame.size.width = ((insets.left + insets.right + img.size.w

[img drawInRect:CGRectIntegral(frame)]; }

NSInteger imageNodeIndex = [_images indexOfObject:imageNode]; if (imageNodeIndex < [_images count] - 1) {

imageNode = [_images objectAtIndex:imageNodeIndex + 1]; } else { break; } } }

CFRelease(ctframe); }

idth ) > self.frame.size.width)? self.frame.size.width : img.size.width;

*通过touch方法来调用代理方法

[objc] view plaincopy

1. 2. 3. 4.

;

- (void)touchesBegan:(NSSet *)touches withEven

t:(UIEvent *)event

{

if (self.delegate && [self.delegate respondsToSelector:@selector(coreTex

tView:receivedTouchOnData:)]) {

CGPoint point = [(UITouch *)[touches anyObject] locationInView:self] NSMutableArray *activeRects;

NSDictionary *data = [self dataForPoint:point activeRects:&activeRec

ts];

if (data.count > 0) {

NSMutableArray *selectedViews = [NSMutableArray new]; for (NSString *rectString in activeRects) { CGRect rect = CGRectFromString(rectString); UIView *view = [[UIView alloc] initWithFrame:rect]; view.layer.cornerRadius = 3; view.clipsToBounds = YES;

5. 6. 7. 8. 9. 10. 11. 12. 13.

14.

;

view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25] [self addSubview:view]; [selectedViews addObject:view]; }

self.touchedData = data;

self.selectionsViews = selectedViews; } }

[super touchesBegan:touches withEvent:event]; }

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

_touchedData = nil;

[_selectionsViews makeObjectsPerformSelector:@selector(removeFromSupervi _selectionsViews = nil;

[super touchesMoved:touches withEvent:event]; }

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

if (_touchedData) {

if (self.delegate && [self.delegate respondsToSelector:@selector(cor if ([self.delegate respondsToSelector:@selector(coreTextView:rec [self.delegate coreTextView:self receivedTouchOnData:_touche } }

_touchedData = nil;

[_selectionsViews makeObjectsPerformSelector:@selector(removeFromSup _selectionsViews = nil; }

[super touchesEnded:touches withEvent:event]; }

15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47.

ew)];

eTextView:receivedTouchOnData:)]) { eivedTouchOnData:)]) { dData];

erview)];

________________________________________________________________________________________________________________________ 2.FTCoreTextStyle 主要是配置属性

2.1 FTCoreTextStyle.h

[objc] view plaincopy

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.

ES.

@property (nonatomic) NSString *name;

e=\> //类型自定义名称

@property (nonatomic) NSString *appendedCharacter;

re\> //

@property (nonatomic) UIFont *font;

>//字体

@property (nonatomic) UIColor *color;

span>//颜色

@property (nonatomic, getter=isUnderLined) BOOL underlined;

e-space:pre\> //是否有下划线

@property (nonatomic) FTCoreTextAlignement textAlignment; //左右对齐方式

@property (nonatomic) UIEdgeInsets paragraphInset;

re\> //段落间隙

@property (nonatomic) CGFloat leading;

span>

@property (nonatomic) CGFloat maxLineHeight;

//行高

@property (nonatomic) CGFloat minLineHeight;

// For bullet styles only

@property (nonatomic) NSString *bulletCharacter;

// Called when the style is parsed for extra actions @property (nonatomic, copy) FTCoreTextCallbackBlock block;

// If NO, the paragraph styling of the enclosing style is used. Default is Y@property (nonatomic, assign) BOOL applyParagraphStyling;

\> //自定义的修饰符

21.

2.2 FTCoreTextStyle.m

初始化方法(实例方法和初始化方法创建)

[objc] view plaincopy

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.

- (id)init {

self = [super init]; if (self) {

_name = @\; _bulletCharacter = @\; _appendedCharacter = @\;

_font = [UIFont systemFontOfSize:12]; _color = [UIColor blackColor]; _underlined = NO;

_textAlignment = FTCoreTextAlignementLeft; _maxLineHeight = 0; _minLineHeight = 0;

_paragraphInset = UIEdgeInsetsZero; _applyParagraphStyling = YES; _leading = 0; _block = nil; }

return self; }

[objc] view plaincopy

1. 2. 3. 4. 5. 6.

+ (id)styleWithName:(NSString *)name {

FTCoreTextStyle *style = [[FTCoreTextStyle alloc] init]; [style setName:name]; return style; }

———————————————————————————————————————————————————————————————————

用法示例

[objc] view plaincopy

1.

FTCoreTextView *coreText

View = [[FTCoreTextView alloc] initWithFrame:CGRectInset(bounds, 20.0f, 0)];

[objc] view plaincopy

1.

coreTextView.dele

gate = self;

[objc] view plaincopy

1. 2. 3.

FTCoreTextStyle *imageStyle = [FTCoreTextStyle styleWithName:FTCoreTextTagIm

age];

imageStyle.textAlignment = FTCoreTextAlignementCenter; [self.coreTextView addStyle:imageStyle];

[objc] view plaincopy

1. 2. 3. 4. 5. 6.

- (void)viewDidLayoutSubviews {

[super viewDidLayoutSubviews];

// We need to recalculate fit height on every layout because // when the device orientation changes, the FTCoreText's width changes

// Make the FTCoreTextView to automatically adjust it's height // so it fits all its rendered text using the actual width [self.coreTextView fitToSuggestedHeight]; }

7. 8. 9. 10. 11.


[无限互联]ios开发之FTCoreText的使用(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2012注册安全工程师考试题及答案(整理版)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: