Ich füge Daten zu TextView
über hinzu. Ich habe ungefähr 30 bis 35 Bilder, die nach einigen Para- oder Datenzeilen hinzugefügt werden, die ich durch NSTextAttachment
gemacht habe. Nun, was ich tun möchte, ist, wo immer es mehr als 2 Bilder gibt, die ich in Carousel View
haben möchte und die restlichen Daten danach. Schau dir meinen Code an. Ich habe den anderen Weg ausprobiert, aber keinen Erfolg. Jede Hilfe wird sehr geschätzt.Karussellansicht in Textansicht hinzufügen
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;
Wie wäre es stattdessen mit uicollectionview? Legen Sie Ihre ersten zwei Bilder in die erste Zelle, die in einer uicollectionviewcell enthalten sind. Dann lass den Rest als gemeinsame Zellen. Ich frage mich, ob ich Ihre Idee richtig verstehe ... – Calios
nicht möglich @Calios. Die App ist anders, ich kann nicht hinzufügen UICollectionView – iDeveloper
* Ich versuchte den anderen Weg, aber nicht Erfolg. * Was genau wollen falsch? –