Programing

iPad에서 UITableView backgroundColor가 항상 회색

crosscheck 2020. 7. 3. 19:45
반응형

iPad에서 UITableView backgroundColor가 항상 회색


backgroundColor대해 설정하면 UITableViewiPhone (장치 및 시뮬레이터)에서는 잘 작동하지만 iPad 시뮬레이터에서는 작동하지 않습니다. 대신에 포함하여 설정 한 모든 색상에 밝은 회색 배경이 나타납니다 groupTableViewBackgroundColor.

재현 단계 :

  1. 새로운 네비게이션 기반 프로젝트를 만듭니다.
  2. RootViewController.xib를 열고 테이블보기 스타일을 "그룹화"로 설정하십시오.
  3. 이 응답자를 RootViewController에 추가하십시오.

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    }
  4. Simulator SDK 3.2를 선택하고 빌드하고 실행하십시오.
  5. 검정색 배경 (장치 및 시뮬레이터)이 나타납니다.
  6. 프로젝트 트리에서 대상을 선택하십시오.
  7. 프로젝트 : iPad 용 현재 대상 업그레이드를 클릭하십시오.
  8. 빌드하고 실행하십시오.
  9. 밝은 회색 배경이 나타납니다.
  10. 테이블 뷰 스타일을 일반으로 되 돌리면 검정색 배경이 나타납니다.

당신의 도움을 주셔서 감사합니다!


이 중 하나를 시도하십시오.

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];

이 솔루션에 감사드립니다. UIViewController에서 IBOutlet을 사용하여 UITableView 속성에 이것을 적용했으며 다음과 같이 잘 작동합니다.

[panelTable setBackgroundView:nil];
[panelTable setBackgroundView:[[[UIView alloc] init] autorelease]];
[panelTable setBackgroundColor:UIColor.clearColor]; // Make the table view transparent

iPad에서는이 backgroundView속성이 그룹화 된 테이블의 회색 배경색을 만드는 데 사용되는 것 같습니다. 따라서 iPad에서 그룹화 된 테이블의 배경색을 변경하려면 속성을 제거한 다음 원하는 테이블보기 를 설정 해야 nil합니다 .backgroundViewbackgroundColor

- (void)viewDidLoad
{
    [super viewDidLoad];

    // If you need to support iOS < 3.2, check for the availability of the
    // backgroundView property.
    if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
        self.tableView.backgroundView = nil;
    }
    self.tableView.backgroundColor = [UIColor whiteColor];
}

Xcode 6.1 및 iOS 8.1 현재, 특히 iPad (셀 배경을 설정하려는 경우)의 경우 테이블 배경 및 셀 배경을 설정 해야하는 것으로 보입니다.

예를 들어, iPhone 스토리 보드에서 셀을 선명한 색상으로 설정 한 다음 배경 이미지가있는 투명한 테이블에 대해 프로그래밍 방식으로 테이블의 배경 이미지를 설정할 수 있습니다. 그러나 iPad에서 동일한 구성을 보려면 셀이 명확하지 않습니다. iPad의 경우 프로그래밍 방식으로 셀을 지우도록 셀을 설정해야합니다.


테이블의 backgroundColor 및 View 설정을 시도했지만 운이 없었습니다 (Xcode 5 iOS7.1 iPad 시뮬레이터) .iPhone에서는 괜찮 았지만 iPad의 밝은 회색 배경색은 ...

셀 자체의 backgroundColor로 작업하면 iOS 7.1 4/2014 에서이 문제가 해결되었습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *CellIdentifier = @"ViewSomeTriggerCell";

        // get a cell or a recycled cell
        sictVCViewSomeTriggerCell *cellTrigger = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        // put a picture and a word in the cell (positions set in .xib)
        NSString * tname = [self.fetchedTriggersArray objectAtIndex:indexPath.row];
        cellTrigger.imageTrigger.image = [UIImage imageNamed:@"icon_appicon.png"];
        cellTrigger.labelName.text = tname;

        // set background color, defeats iPad wierdness
        // http://stackoverflow.com/questions/2688007/uitableview-backgroundcolor-always-gray-on-ipad

        // clearColor is what I wanted, and it worked, also tested with purpleColor
        cellTrigger.backgroundColor =[UIColor clearColor];
        return cellTrigger;

}


응용 프로그램이 iPhone과 iPad를 모두 대상으로하는 경우 다음과 같이 할 수 있습니다.

[myTableView setBackgroundColor:[UIColor clearColor]]; // this is for iPhone

if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone) {
    [myTableView setBackgroundView:nil];
    [myTableView setBackgroundView:[[UIView alloc] init]];
} // this is for iPad only

TableView alloc에는 ARC에 대한 자동 릴리스가 없습니다.


If you are adding a UIViewController to another UIViewController you also need to set your view's background to clearColor in addition to UITableView or else you will get a white background instead of light grey.

if ([myViewController.myTableView respondsToSelector:@selector(setBackgroundView:)]) {
    [myViewController.myTableView setBackgroundView:nil];
}
myViewController.myTableView.backgroundColor = [UIColor clearColor];
myViewController.view.backgroundColor = [UIColor clearColor];

  • Simulating iPad 2
  • Running iOS 7.1 through 8.3
  • Built from XCode 6.3

None of the above worked for my UIViewController->UITableView specified using a single XIB. What did work was moving the whole setup into a Storyboard, and setting the background color using the IB inspector.


I also got this kind of problem. The UITableView background color will be always groupTableViewBackgroundColor no matter what I set.

The symptom is like this issue - UITableView is resetting its background color before view appears

After I set the background color in init function, it is correct. In viewDidLoad and viewWillAppear stage, it is correct. However, in viewDidAppear, the background color is reset to its default color.

The accepted answer does not work now.

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[UIView alloc] init]];

Here is my solution. Just set the tableView's background color in viewDidLoad function rather than init or viewWillAppear.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor clearColor];
}

참고URL : https://stackoverflow.com/questions/2688007/uitableview-backgroundcolor-always-gray-on-ipad

반응형