2014-10-15 10 views
2

UITextView 내에서 NSTextAttachment 이미지의 가로 위치를 변경하려고합니다. 나는 설정을 시도했다NSTextAttachment 커닝

[attributedString setAttributes:@{NSKernAttributeName:@(1.5)} range:NSMakeRange(0, 1)]; 

이것은 단순히 적절한 커닝 공간을 제공하면서 첨부 파일을 사라지게한다. 나는 또한 원점 x 좌표를 변경하려고 시도했다.

- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex 

이것은 부착물의 수평 위치에는 영향을 미치지 않는다. 알려주십시오.

답변

0

textAttachment.bounds 속성을 사용하여 NSTextAttachment 이미지의 가로 위치를 설정할 수 있습니다.

NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init]; 
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"YourImageURL"] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60]; 
NSData *urlData=[NSURLConnection sendSynchronousRequest:imageRequest returningResponse:nil error:nil]; 
UIImage * image = [UIImage imageWithData:urlData]; 
if (image != nil) { 
textAttachment.image = image; 
} else { 
textAttachment.image =[UIImage imageNamed:@"YourPlaceHolderImageName"]; 
      } 
textAttachment.bounds = CGRectMake(0,-4, textAttachment.image.size.height, textAttachment.image.size.width);