logo
down
shadow

Adjusting Height of UITableViewCell


Adjusting Height of UITableViewCell

By : user2956772
Date : November 22 2020, 03:03 PM
will be helpful for those in need This is a bit of a frustrating thing, but it's definitely doable. There are several ways to do this, but the way I have chosen as my default method is to set it up in the following way:
Create all of my cells in code. This gives me the benefit of having more explicit control over everything. This is not necessarily better, but I like it better because it makes the entire process more intuitive to me.
code :
// UITableViewController
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    PFObject *item = self.items[indexPath.row];
    return [ItemTableViewCell heightNeededForItem:item];
}
- (ItemTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ItemTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    PFObject *item           = self.items[indexPath.row];
    [cell configureForItem:item];
    return cell;
}


// UITableViewCell Subclass

// Header file
#import <UIKit/UIKit.h>
@interface ItemTableViewCell : UITableViewCell {

}

#pragma mark - 
#pragma mark - Public Class Methods
+ (CGFloat)heightNeededForItem:(PFObject *)item;

#pragma mark -
#pragma mark - Public Instance Methods
- (void)configureForItem:(PFObject *)item;

@end

// Implementation file
// Header import
#import "ItemTableViewCell.h"

@interface ItemTableViewCell () {

}

#pragma mark -
#pragma mark - UI Controls
@property (strong, nonatomic) UILabel *detailLabel;

@end
@implementation ItemTableViewCell

#pragma mark -
#pragma mark - Initialization
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUserInterface];
    }
    return self;
}

#pragma mark -
#pragma mark - Public Class Methods
+ (CGFloat)heightNeededForItem:(PFObject *)item {
    NSString *detailString = item[@"property"];
    CGFloat availableWidth = // perhaps just the screen width; maybe more advanced logic here (e.g., if using cell accessories)

    UIFont *detailFont     = [self detailLabelFont];
    CGSize detailSize      = [detailString boundingRectWithSize:CGSizeMake(availableWidth, MAXFLOAT)
                                                        options:NSStringDrawingUsesLineFragmentOrigin
                                                     attributes:@{NSFontAttributeName: detailFont}
                                                        context:nil].size;

    return [self topBottomMargin] + detailSize.height + [self topBottomMargin];
}

#pragma mark -
#pragma mark - "Methodized" Class Properties
+ (CGFloat)leftRightMargin {
    return 16.0f;
}
+ (CGFloat)detailLabelFontSize {
    if (IS_IPHONE_4 || IS_IPHONE_5) {
        return 14.0f;
    } else if (IS_IPHONE_6) {
        return 17.0f;
    } else if (IS_IPHONE_6PLUS) {
        return 20.0f;
    } else {
        return 24.0f;
    }
}
+ (CGFloat)topBottomMargin {
    return 16.0f;
}
+ (UIFont *)detailLabelFont {
    return [UIFont systemFontOfSize:[self detailLabelFontSize]];
}

#pragma mark -
#pragma mark - Public Instance Methods
- (void)configureForItem:(PFObject *)item {
    // This could be very advanced...
    self.detailLabel.text = item[@"property"];
}

#pragma mark -
#pragma mark - UI Setup
- (void)setupUserInterface {
    [self createControls];
    [self setupControls];
    [self layoutControls];
}
- (void)createControls {
    self.detailLabel    = [[UILabel alloc] init];
}
- (void)setupControls {        
    self.detailLabel.font   = [ItemTableViewCell detailLabelFont];
    // This is necessary for a pure auto layout scenario
    [self.detailLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
}
- (void)layoutControls {
    [self.contentView addSubview:self.detailLabel];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(margin)-[label]-(margin)-|"
                                                                             options:0
                                                                             metrics:@{@"margin"    : @([ItemTableViewCell leftRightMargin])}
                                                                               views:@{@"label"     : self.detailLabel}]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(margin)-[detail]-(margin)-|"
                                                                             options:0
                                                                             metrics:@{@"margin"    : @([ItemTableViewCell topBottomMargin])}
                                                                               views:@{@"detail"    : self.detailLabel}]];
}
@end


Share : facebook icon twitter icon
Adjusting the positions of the labels in a UITableViewCell

Adjusting the positions of the labels in a UITableViewCell


By : user1407141
Date : March 29 2020, 07:55 AM
this one helps. You'll want a custom UITableViewCell subclass that overrides layoutSubviews to do the dirty work of laying out whatever subviews are in there. Calling super then adjusting the detailTextLabel.frame is probably the easiest thing to do.
Automatically adjusting UITableView height to display only the UITableViewCell(s) present

Automatically adjusting UITableView height to display only the UITableViewCell(s) present


By : Cengiz Ceylan
Date : March 29 2020, 07:55 AM
wish of those help You can use the table view's content size to determine how much space the table wants.
code :
CGFloat height = myTableView.contentSize.height;
Adjusting rows to content height in dynamic height grid

Adjusting rows to content height in dynamic height grid


By : Adeel Malik
Date : March 29 2020, 07:55 AM
hope this fix your issue For the two content items, use min-content for each row. This will size each row based on a "shrink-to-fit" algorithm.
To give the right column full height, add an empty implicit row.
code :
body {
  margin: 0; font-family: arial;
}
* { box-sizing: border-box; }

.wrapper {
  height: 100vh;
  display: grid;
  grid-template-rows: 40px 1fr 40px;
  grid-gap: 5px;  
  grid-template-areas: "header  header  header" 
                       "content content content"
                       "footer  footer  footer";

}

header {
  grid-area: header;
  background-color: black;
  color: white;
  padding: 10px;
}

footer {
  grid-area: footer;
  background-color: black;
  color: white;
  padding: 10px;
}

.container {
  grid-area: content;
  display: grid;
  grid-template-columns: 820px 1fr;
  grid-template-rows: min-content min-content; /* shrink-to-fit */
  grid-gap: 5px;
  padding: 0 5px;
  grid-template-areas: "green red" 
                       "purple red"
                       "   .    red"; /* implicit row; for red's full height */

}

.grid-item-1 {
  grid-area: green;
  color: #fff;
  text-align: center;
  padding: 10px;
  background-color: #009036;
}

.grid-item-2 {
  grid-area: purple;
  color: #fff;
  text-align: center;
  padding: 10px;
  background-color: #772164;
}

.grid-item-3 {
  grid-area: red;
  color: #fff;
  text-align: center;
  background-color: #C91B18;
}
<section class="wrapper">
  <header>Header</header>
  <div class="container">
    <div class="grid-item-1">This row height fit according data.
      <br>
      <br>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
      dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
    <div class="grid-item-2">
      This row height fit according data.
      <br>
      <br>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
      dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
    <div class="grid-item-3">3</div>
  </div>
  <footer>Footer</footer>
</section>
UITableViewCell's content view height is not adjusting for the dynamic font (NSLayoutConstraints)

UITableViewCell's content view height is not adjusting for the dynamic font (NSLayoutConstraints)


By : Manju
Date : March 29 2020, 07:55 AM
Hope that helps I am having difficulties adjusting table view cells to automatically resize for dynamic type fonts. Note that I am using layout constraints in code, not in storyboard. , Add all the views to the contentView!
code :
contentView.addSubview(yourView)
segmentDataLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 20).isActive = true
segmentDataLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -20).isActive = true
How to give percentage to UITableViewCell height base on the height of UITableView? Then All UITableViewCell can show ou

How to give percentage to UITableViewCell height base on the height of UITableView? Then All UITableViewCell can show ou


By : Ted Bridgman
Date : March 29 2020, 07:55 AM
Hope this helps First make a property for numberOfRows to be returned in tableView. Let's say rowCount is the property name. Then
Related Posts Related Posts :
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • Adding checkmark to selected table cell also checks another table cell
  • UICollectionView cellForItemAtIndexPath indexPath row is nil
  • Resize and set quality on JPEG image while retaining EXIF in iOS
  • How to push rootviewcontroller in Ios
  • How to add UIBarbuttonItem at centre on UInavigationbar in iOS
  • Would this IOS device test crash be expected
  • PickerView not showing any values
  • How to set root view controller in storyboard animated with navigation controller programmatically
  • Can anyone suggest me the effective way to deal with s3 upload fail because of timezone difference issue?
  • Getting list of files in documents folder
  • Error while using Realm Object as a singleton. Is it a good idea?
  • inserting into SQLite database
  • More nodes than I should
  • Facebook IOS SDK navigate to another controller after login not working
  • Swift Array - use "Contains" of type AnyObject
  • Sidebar menu with indicate navigationbar on iOS
  • Programmatically set size of UIView from Storyboard
  • Navigation bar blink
  • Web services issue on POST method
  • Parse.com error 'Method not allowed when Pinning is enabled.' when I use a PFQueryTableViewController subclass
  • Swift can't send URLRequest at all?
  • No Provisiong profiles with a valid signing identity were found and Failed to locate or generate matching signing assets
  • iOS: how to set httponly flag for NSHTTPCookie
  • How to get the mac address of a beacon in objective-c without knowing its UUID, major and minor values?
  • tableView is not showing data from JSON in swift
  • iTunes reject app for date of birth
  • SWIFT reporting "Extra argument in call" - works in Playground
  • save data depending on passed value in swift
  • webview not showing on full Screen of iphone 6
  • Location Notification's based on Latest iOS Feature
  • How to show five digit unicode in iphone
  • unwind doesn't work
  • Confusion about coordinates, frames & child nodes in SpriteKit on iOS?
  • If Statements not being recognized by Xcode
  • readonly property in RubyMotion
  • 'No available types for source 1' when the app runs on my device(IPhone 6) swift
  • IOS:Remove view when clicked in background
  • Removing "\" from URL in iOS Swift
  • iOS - Send an email automatically (NOT from user's account)
  • The usage of NSNotificationCenter in the relationship of parent and children
  • When do Apple auto-renewable subscriptions renew?
  • Unknown large spacing between x-axis label and base of plot in core-plot
  • How do I change the displayed time format after NSTimer is initiated?
  • Swift JSON breaks when [ ] are used
  • Secure Memory For Swift Objects
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org