Я добавляю данные в TextView
через sqlite database
. У меня есть от 30 до 35 изображений, которые будут добавлены в него после некоторой Пара или Линии данных, которые я сделал через NSTextAttachment
. Теперь, что я хочу сделать, там, где есть больше двух изображений, я хочу, чтобы он находился в Carousel View
и оставил после него данные. Посмотрите на мой код. Я пробовал по-другому, но не добился успеха. Любая помощь будет высоко ценится.Добавить карусель Просмотр внутри Textview
NSTextAttachment *textAttachment1 = [[NSTextAttachment alloc] init];
textAttachment1.image = [UIImage imageNamed:@"img1.png"];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage imageNamed:@"img2.png"];
NSTextAttachment *textAttachment2 = [[NSTextAttachment alloc] init];
textAttachment2.image = [UIImage imageNamed:@"img3.png"];
NSTextAttachment *textAttachment3 = [[NSTextAttachment alloc] init];
CGFloat oldWidth1 = textAttachment1.image.size.width;
CGFloat oldWidth = textAttachment.image.size.width;
CGFloat oldWidth2 = textAttachment2.image.size.width;
CGFloat scaleFactor1 = oldWidth1/(self.textViewResearch.frame.size.width + 70);
CGFloat scaleFactor = oldWidth/(self.textViewResearch.frame.size.width + 70);
CGFloat scaleFactor2 = oldWidth2/(self.textViewResearch.frame.size.width + 70);
textAttachment1.image = [UIImage imageWithCGImage:textAttachment1.image.CGImage scale:scaleFactor1 orientation:UIImageOrientationUp];
textAttachment.image = [UIImage imageWithCGImage:textAttachment.image.CGImage scale:scaleFactor orientation:UIImageOrientationUp];
textAttachment2.image = [UIImage imageWithCGImage:textAttachment2.image.CGImage scale:scaleFactor2 orientation:UIImageOrientationUp];
NSAttributedString *attrStringWithImage1 = [NSAttributedString attributedStringWithAttachment:textAttachment1];
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
NSAttributedString *attrStringWithImage2 = [NSAttributedString attributedStringWithAttachment:textAttachment2];
[attributedString replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attrStringWithImage1];
[attributedString replaceCharactersInRange:NSMakeRange(13740, 0) withAttributedString:attrStringWithImage];
[attributedString replaceCharactersInRange:NSMakeRange(13741, 0) withAttributedString:attrStringWithImage2];
self.textView.attributedText = attributedString;
Как насчет использования uicollectionview вместо этого? Поместите первые два изображения в первую ячейку, которые содержатся в ячейке uicollectionviewcell. Затем оставьте остальные как обычные ячейки. Интересно, правильно ли я понял ... – Calios
невозможно @Calios. Приложение отличается тем, что я не могу добавить UIColllectionVIew – iDeveloper
* Я пробовал по-другому, но не добился успеха. * Что именно не так? –