0

SQLite DBのテキストビューにテキストを表示するこのコードがあります..

NSMutableString *combined = [NSMutableString string];
for(NSUInteger idx = 0; idx < [delegate.allSelectedVerseEnglish count]; idx++) {
    [combined appendFormat:@" %d   %@", idx, [delegate.allSelectedVerseEnglish objectAtIndex:idx]];
}

self.multiPageView.text = combined;
self.multiPageView.font = [UIFont fontWithName:@"Georgia" size:self.fontSize];

delegate.allSelectedVerseEnglishですNSArray multiPageView_UITextView

上記のループ関数を配置して、テキストに従って数値を取得します。たとえば、 テキストの間にUIButton1 hello 2 iPhone 3 iPad 4 mac etc etc..が必要なだけです。たとえば、そこからいくつかのタッチイベントを作成する必要があるためです。前もって感謝します。1 2 3 4 ..unbutton hello unbutton iPhone etc etc

4

1 に答える 1

1

UIButtons を textview のテキストの間に配置したい場合は、すぐ上に別のビューとして配置する以外に方法はありません。そのため、これらのボタンの下にスペースを追加する必要があります。その量は、ボタンのサイズに基づいて自分で計算する必要があります。したがって、次のようなものを表示したい場合:

Press here [UIButton] or here [Another UIButton],

テキスト文字列は次のようになります

Press here            or here                   ,

そのため、それらの場所にボタンを追加すると、希望どおりに表示されます。

アップデート

ここにはさらにコードが必要なように思われるので、以下に示します。まず、文字のサイズを計算する必要があります。10 ピクセルの高さと 8 ピクセルであると仮定しましょう。いいえ、それをletterHeightletterWidthと呼びましょう。また、64x10 ピクセルのボタンが必要であると仮定しましょう。そのため、ボタンの後ろに 64/8=8 +2 個のスペースが必要です (その周りに境界線を作成するには 2 個)。

NSMutableString *combined = [NSMutableString string];
int letterHeight = 10;
int letterWidth = 8;
   for(NSString *verse in delegate.allSelectedVerseEnglish) {
       [combined appendFormat:@"          %@",verse];//10 spaces there
//You have to experiment with this, but idea is that your x coordinate is just proportional to the length of the line you are inserting your button in, and y is proportional to number of lines
    int xCoordinate = [combined length]*letterWidth%(int)(self.multiPageView.frame.size.width);
    int yCoordinate = [combined length]*letterWidth/(int)(self.multiPageView.frame.size.width)*letterHeight;
    
     UIButton *newButton = [[UIButton alloc]initWithFrame:CGRectMake(xCoordinate,yCoordinate,64,10)];
     [self.multiPageView addSubview:newButton];
}
 self.multiPageView.text = combined;
于 2012-04-22T17:08:25.973 に答える