난 대물-C에 새로 온 .. I가 UILabels
의 .I 동적 크기 (width
및 height
)를 설정할 계세요하지만에 텍스트와 UILabel
이 텍스트는 그것이에 맞는 doesnot 경우 올바르게 표시해야 큰 그 다른 라인으로가는 한 줄 및 데이터가 완료되면 다음 UILabels
데이터 만 시작하고 다음에 대한 동일한 개념을 시작합니다 UILabel
. 어떻게해야합니까? 이 많은 도움 월에 이어동적 크기를 xcode의 UILabels로 설정 하시겠습니까?
0
A
답변
1
viewcontroller.m 파일의 코드
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
items = [[NSMutableArray alloc] init];
[items addObject:@"Happiness is having a large, loving, caring, close-knit family in another city.\n\n\t\t-George Burns (1896 - 1996)"];
[items addObject:@"When I am abroad, I always make it a rule never to criticize or attack the government of my own country. I make up for lost time when I come home.\n\n\t\t-Sir Winston Churchill (1874 - 1965)"];
[items addObject:@"After two years in Washington, I often long for the realism and sincerity of Hollywood.\n\n\t\t-Fred Thompson, Speech before the Commonwealth Club of California"];
[items addObject:@"It is a profitable thing, if one is wise, to seem foolish.\n\n\t\t-Aeschylus (525 BC - 456 BC)"];
[items addObject:@"Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions.\n\n\t\t-Dave Barry"];
[items addObject:@"At the worst, a house unkept cannot be so distressing as a life unlived.\n\n\t\t-Dame Rose Macaulay (1881 - 1958)"];
[items addObject:@"It is curious that physical courage should be so common in the world and moral courage so rare.\n\n\t\t-Mark Twain (1835 - 1910)"];
[items addObject:@"The knowledge of the world is only to be acquired in the world, and not in a closet.\n\n\t\t-Lord Chesterfield (1694 - 1773), Letters to His Son, 1746, published 1774"];
[items addObject:@"What lies behind us and what lies before us are tiny matters compared to what lies within us.\n\n\t\t-Ralph Waldo Emerson (1803 - 1882), (attributed)"];
}
#pragma mark -
#pragma mark UITableView Delegaates
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [items count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text 1="systemFontOfSize:FONT_SIZE" language="sizeWithFont:[UIFont"][/text] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
CGFloat height = MAX(size.height, 44.0f);
return height + (CELL_CONTENT_MARGIN * 2);
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UILabel *label = nil;
cell = [tv dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode:NSLineBreakByWordWrapping];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];
[[cell contentView] addSubview:label];
}
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text 1="systemFontOfSize:FONT_SIZE" language="sizeWithFont:[UIFont"][/text] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
if (!label)
label = (UILabel*)[cell viewWithTag:1];
[label setText:text];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[dataTableView deselectRowAtIndexPath:[dataTableView indexPathForSelectedRow] animated:YES];
}
@end
Also Download Source code from here.
다음은 viewcontroller.h 파일
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
IBOutlet UITableView *dataTableView;
NSMutableArray *items;
}
@end
에 대한 코드입니다. 여기 링크는 "TEXTSIZE"를 사용
0
관련 문제
- 1. QBoxLayout 최대 크기를 설정 하시겠습니까?
- 2. InlineUIContainer의 크기를 설정 하시겠습니까?
- 3. Layered Drawable의 크기를 설정 하시겠습니까?
- 4. CSS만으로 동적 너비를 설정 하시겠습니까?
- 5. Xcode의 창 너비 설정
- 6. 버튼의 상대적 크기를 강제 설정 하시겠습니까?
- 7. 프로그래밍 방식으로 원격 ImageVue?의 픽셀 크기를 설정 하시겠습니까?
- 8. 동적 페이징을 gridview로 설정
- 9. 동적 사용자 정의보기의 크기를 고려한 버튼의 크기 설정
- 10. 어떻게 설정 하시겠습니까? 이미지 클립 크기를 조정하지 않고 클리핑을 기본으로하는 클립을 설정 하시겠습니까?
- 11. 2D 배열 크기를 확장 하시겠습니까?
- 12. Xcode의 대상을 iPad가 아닌 iPad로 설정
- 13. Xcode의 프로젝트 빌드 설정에서 대상 빌드 설정
- 14. 이미지 크기를 HTML로 설정
- 15. 픽셀을 사용하여 Android에서 위치 및 크기를 설정 하시겠습니까?
- 16. 삼성 스마트 TV 응용 프로그램의 배경 이미지 크기를 설정 하시겠습니까?
- 17. Flex BubbleChart - 차트 크기와 관련하여 버블 크기를 설정 하시겠습니까?
- 18. Umbraco CMS. 업 로더에서 이미지 크기를 설정 하시겠습니까?
- 19. Silverlight 3 브라우저를 벗어남 : 호스트 창 크기를 설정 하시겠습니까?
- 20. URL에서 UIImage를로드 할 때 UITableViewCell에서 UIImageView 크기를 설정 하시겠습니까?
- 21. Java - JEditorPane에서 선택 영역의 글꼴 크기를 설정 하시겠습니까?
- 22. 프레임 크기에 따라 UILabel 글꼴 크기를 설정 하시겠습니까?
- 23. Jpanel 프로그램에서 Jframe의 크기를 설정 하시겠습니까? JPanel의 프로그램에서
- 24. 스크롤링 패널의 동적 높이 설정?
- 25. 여유롭게 DIV 크기를 조정 하시겠습니까?
- 26. iphone 앱/xcode의 시각적 자산
- 27. 화면 크기를 확인 하시겠습니까?
- 28. 레포 크기를 결정 하시겠습니까?
- 29. NSWindow 크기를 고정 하시겠습니까?
- 30. IKImageView 크기를 조정 하시겠습니까?
내 대답은 http://stackoverflow.com/a/12600584/1538079 –
가능한 중복 여기에 주어진 체크 레이블 프레임과 backview을 설정합니다 [동적으로 UILabel 높이를 계산하는 방법?] (http://stackoverflow.com/questions/7174007/how-to-calculate-uilabel-height-dynamically) –