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.