Browse Source

updated demo

ibireme 9 years ago
parent
commit
81dc32b2e7
2 changed files with 10 additions and 13 deletions
  1. 4 0
      Demo/YYTextDemo/YYTextEmoticonExample.m
  2. 6 13
      YYText/Component/YYTextLayout.m

+ 4 - 0
Demo/YYTextDemo/YYTextEmoticonExample.m

@@ -40,11 +40,15 @@
     YYTextSimpleEmoticonParser *parser = [YYTextSimpleEmoticonParser new];
     parser.emoticonMapper = mapper;
     
+    YYTextLinePositionSimpleModifier *mod = [YYTextLinePositionSimpleModifier new];
+    mod.fixedLineHeight = 22;
+    
     YYTextView *textView = [YYTextView new];
     textView.text = @"Hahahah:smile:, it\'s emoticons::cool::arrow::cry::wink:\n\nYou can input \":\" + \"smile\" + \":\" to display smile emoticon, or you can copy and paste these emoticons.\n";
     textView.font = [UIFont systemFontOfSize:17];
     textView.textParser = parser;
     textView.size = self.view.size;
+    textView.linePositionModifier = mod;
     textView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
     textView.delegate = self;
     if (kiOS7Later) {

+ 6 - 13
YYText/Component/YYTextLayout.m

@@ -39,26 +39,19 @@ static inline UIEdgeInsets UIEdgeInsetRotateVertical(UIEdgeInsets insets) {
 
 @implementation YYTextLinePositionSimpleModifier
 - (void)modifyLines:(NSArray *)lines fromText:(NSAttributedString *)text inContainer:(YYTextContainer *)container {
-    CGFloat top = 0;
     if (container.verticalForm) {
         for (NSUInteger i = 0, max = lines.count; i < max; i++) {
             YYTextLine *line = lines[i];
-            if (i == 0) top = line.position.x;
-            else {
-                CGPoint pos = line.position;
-                pos.x = top - (line.row * _fixedLineHeight);
-                line.position = pos;
-            }
+            CGPoint pos = line.position;
+            pos.x = container.size.width - container.insets.right - line.row * _fixedLineHeight - _fixedLineHeight * 0.9;
+            line.position = pos;
         }
     } else {
         for (NSUInteger i = 0, max = lines.count; i < max; i++) {
             YYTextLine *line = lines[i];
-            if (i == 0) top = line.position.y;
-            else {
-                CGPoint pos = line.position;
-                pos.y = top + (line.row * _fixedLineHeight + top);
-                line.position = pos;
-            }
+            CGPoint pos = line.position;
+            pos.y = line.row * _fixedLineHeight + _fixedLineHeight * 0.9 + container.insets.top;
+            line.position = pos;
         }
     }
 }