How do you create buttons like the "Settings", "Notifications", and "Cash Out" buttons in venmo shown below? Also, is the scroll view they use just a UIScrollView or a modified UITableView? I can't figure out how to add things like the buttons or the picture with balance info and name to a UITableView.
For this example, I think it's easier to use a UITableView than to build a custom subclass of UIScrollView. If you want to customize the look of the table view's cells, initialize the table view with the UITableViewStylePlain style and give each UITableViewCell the appropriate backgroundView & selectedBackgroundView in –[UITableViewDataSource tableView:cellForRowAtIndexPath:].
For the "Settings," "Notifications," and "Cash Out" buttons, just add them as subviews of the cell in the first row of the first section. Use -[UIButton setTitle:forState:] & -[UIButton setImage:forState:] to give each button a title & image, respectively. Set the UIButton properties titleEdgeInsets and/or imageEdgeInsets so that each button's title appears below its image.
To add a picture with a name, bio, and balance at the top, use the tableHeaderView property of UITableView. In -[UIViewController viewDidLoad], initialize a UIView *tableHeaderView with the desired height and give it subviews, e.g., pictureButton, nameLabel, bioTextView, balanceLabel. Then, do self.tableView.tableHeaderView = tableHeaderView.
They have used tableView. It contains 3 sections. They have chaged customCell in each section. In cellForRow delegate method you get section. Accordingly you can change cells. In CustomCell you can add any view like buttons.
Related
I want to add button or row end of uitableview. I used tableview footer but its not solution for me. I also tried others way but ı didnt found any result. How can ı pass this problem.
Thanks..
Use UIViewController instead of UITableViewController:
In storyboard add UITableView to your view controller
Create an IBOutlet for UITableView - connect it
Conform your view controller to UITableViewDelegate and UITableViewDataSource
set tableView.delegate = self and tableView.dataSource = self
In storyboard add a button bellow table view and set top button's constraint to be few (e.g. 4) points away from table view's bottom constraint
Create IBOutlet for button and connect it
Add height constraint for your button - set it to 0.0
Set button's title to empty string ("")
Create IBOutlet for button's height constraint and connect it
Check when your table view reaches the end - to check whether your table reached the bottom you can implement tableView:willDisplayCell:forRowAtIndexPath: and check if indexPath.row is the last item in your data source (there are other ways too so you are free to check them)
When your table reached the end - simply set button's title to your desired title with button.setTitle(for) and animate button's constraint to another height (big enough to see the whole button)
When button is pressed you can just do the opposite animation: set button's title to "" and animate height constraint change back to 0.0
I am having a custom cell where I add a UIImageView as a subview for the cell's contentView.
This UIImageView is placed outside the boundaries of the cell which results with image appearing underneath the table view separator as follows:
I wish that the image will override the table view separator as follows:
How can I do that?
That you can't do with tablview's separator. You first need to hide tableview's separator (i.e set seperator to none from IB or you can set to none by code also).
Take UIView with same width of separator and with height = 1 or 2 if want thick separator. And put it to the end of contentview of cell.
The easiest way is to default separators in tableview and add a simple uiview line as a subview to your cell below your image view.
I have a UIViewController with a calendar and below it is a UITableView with a UITableViewCell that has a series of UIButtons that I change the button text depending on the data that I retrieve. When a date is selected I update a NSArray and call [self.tableView reloadData]. The first row populates as it should, the UIButton titles show the correct data. The rest of the rows show the default values for the UIButtons from the storyboard. If I scroll a cell off the screen and let it come back it displays the correct data (i.e. updates the titles of the UIButtons). I'm not sure why this is happening. I tried adding
[cell setNeedsLayout] before the cell is returned but it has not helped.
Are you modifying the testLabels directly? UIButtons have iffy behavior sometimes if you do. Try using the UIButton methods to change the textLabel's properties, such as setTitle: forState:
I've created a tableview within Viewcontroller and inserted disclosure indicator, but it is not showing, because the right margin is not correct.
What I tried:
selecting table and click in xCode on "pin" button and set left and right to 0, select there all frames in container and clicked: add constraints
but without results.
How can i fix this?
I attached the problem as image. (i have added a frame to focus the problem)
Okay, there can be multiple reasons for which this can happen. For instance, one can forget to deck the cell with wrong identifier or may have set the accessory Indicator in a wrong way. My personal assumption is you probably have set constrain improperly.
So, I am just going to show you the whole process.
Step 1: Drag and UITableView inside your ViewController and drag a UITableViewCell inside that TableView. Select the Table View Cell and assign an identifier. Make sure, in your datasource method, -cellForRowAtIndexPath, you use this same identifier.
Step 2: Go to your View Controller and take an IBOutlet of a UITableView.
#interface MyViewController : UIViewController<UITableViewDataSource>
#property(nonatomic, strong) IBOutlet UITableView *myTableView;
#end
Step 3: Go to the connection Inspector of your storyboard and connect the UITableView with this outlet.
Step 4: Go to the implementation file of your View Controller and populate the datasource methods. Also make sure, you set your TableView's datasource to your view controller.
Now when you build and run this code you won't see the accessory Indicator.
The reason is you didn't set the constraints.
Step 4: Just set the constrains like the following and you are good to go.
This is my final view.
You need to change seperator inset inorder to remove left margin. Its set to default change it to custom and make left insets and right insets to zero. You can set the 'Separator Inset' from the storyboard:
Change Seperator insets to Custom and make left to zero
Try to programmatically set the width and height of the tableView like so...
#IBOutlet weak var resultsTable: UITableView! // connect to tableView
override func viewDidLoad() {
super.viewDidLoad()
let theWidth = view.frame.size.width
let theHeight = view.frame.size.height
resultsTable.frame = CGRectMake(0,0, theWidth, theHeight)
}
The problem was not the margin/layout.
To show disclosure indicator in tableview cell's, it is needed to select disclosure indicator from Accessory menu AND give a identifier for the cell.
Without given identifier the disclosure indicator is not showing.
I've subclassed UITableViewCell to display a UIImage and two UILabel subviews. In the view controller for the table view, in the method cellForRowAtIndexPath: I've enabled an accessory view via setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton.
Cells display correctly.
When I tap on the accessory disclosure button I want to replace the two label subviews with two different label subviews. My approach was the following:
In the subclassed UITableViewCell, inside layoutSubviews, create the
CGRects for the "alternate" labels, position them in the same
places as the two "original" label and hide them via setAlpha:;
When the disclosure button is tapped swap out the set of two
label by adjusting their respective alphas.
The problem is I can't figure out what logic in layoutSubviews I'd use to know whether the accessory button has been tapped. I see that in the view controller accessoryButtonTappedForRowWithIndexPath: is called when that button is tapped and from there it seems like I would call layoutSubviews but can't figure out how to use that fact to accomplish what I'm trying to do.
Am I going about this all wrong? Instead of hiding/showing CGRects with alpha should I simply be creating another subclass of UITableViewCell?
When I tap on the accessory disclosure button I want to replace the two UILabel subviews with two different UILabel subviews.
I'll do the following. Create a public method in your UITableViewCell subclass like the following:
- (void)changeContentForCell;
In this method you could set the contentView as you prefer.
Then in your view controller implement
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
CustomCell* cCell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];
[cCell changeContentForCell];
}
This is a simple example for change the content. In my opinion you don't have to use layoutSubviews to add views.
Leave this logic in changeContentForCell and then call setNeedsLayout to change your layout. Maybe you could have a variable that tracks the state for your cell: normal state or modified state.
Hope it helps.