음,이 해야지 원하는 폭에 맞는 마스터 문자열의 하위 문자열을 얻기 위해 일할 : 물론
//masterString is your long string that you're looking to break apart...
NSString *tempstring = masterString;
while (someLabel.bounds.size.width < [tempString sizeWithFont:someLabelLabel.font].width) {
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:[tempString componentsSeparatedByString:@" "]];
//Remove the last object, which is the last word in the string...
[tempArray removeLastObject];
//Recreate the tempString with the last word removed by piecing the objects/words back together...
tempString = @"";
for (int i=0; i < tempArray.count - 1; i++) {
tempString = [tempString stringByAppendingFormat:@"%@ ", [tempArray objectAtIndex:i]];
}
//You must append the last object in tempArray without the space, or you will get an infinite loop...
tempString = [tempString stringByAppendingFormat:@"%@", [tempArray objectAtIndex:tempArray.count - 1]];
}
//Now do whatever you want with the tempString, which will fit in the width desired...
, 이것은 당신이 분리가 줄 바꿈을 사용하여 발생 할 가정한다. 당신이 단어를 생각하지 않으면 자신이 완벽하게 원하는 폭을 차지하기 위해 (문자 랩 즉), 대신 이렇게 따로 따로 잘라 되 :
NSString *tempstring = masterString;
while (someLabel.bounds.size.width < [tempString sizeWithFont:someLabelLabel.font].width) {
tempString = [tempString substringToIndex:tempString.length - 1];
}
//Now do whatever you want with the tempString, which will fit in the width desired...
남은 문자열의 나머지 조각을 얻기 위해, 다음을 수행하십시오 :
NSString *restOfString = [masterString substringFromIndex:tempString.length];
희망이 있습니다. 나는이 코드를 제대로 테스트하지 못했다는 것을 인정해야한다. 비록 과거에 비슷한 일을 해왔다. ...
어떻게하면 이미지 주위에 텍스트를 감쌀 수 있을까? – Adam
^^ sry, 나는 sth을 놓쳤다 ... (내 의견을 삭제할 것입니다) – thomas