Custom UITableViewCell Edit View - ios

I've been looking over countless questions and answers here on SO, but could not find one that would provide the answer for my specific problem.
In a nutshell: I am trying to implement a custom edit view for my UITableViewCells. I would like to keep the basic "delete" and "rearrange/drag" actions (although on opposite ends than in the default implementation and with custom icons), and I would also like to add a "duplicate" action to them and one that navigates to a specific view (separate from the one when you click the cell in normal state). Something like this:
Ideally, I would like to trigger this edit mode on all cells when I toggle edit mode with a separate button, and on individual cells with a left swipe (without the drag option if it is not possible on an individual cell).
I have sub-classed UITableViewCell and was able to add a swipe recognizer that reveals a view ("cellOptionsContainer") with the 3 custom buttons on the right, all of which I was able to make work using tags and delegates, but that is most certainly not the right way to do things because I've added them to the cell's content view (not knowing any better):
// Add container to hold options buttons
cellOptionsContainer = [[UIView alloc] initWithFrame:CGRectMake(cellWidth,
0.0f,
(dataBase.sizeInteraction * 3),
dataBase.sizeInteraction)];
[self.contentView addSubview:cellOptionsContainer];
// Add edit button
UIButton *cellOptionsButton = [[UIButton alloc] initWithFrame:CGRectMake((0.0f),
0.0f,
dataBase.sizeInteraction,
dataBase.sizeInteraction)];
cellOptionsButton.tag = cellID;
[cellOptionsButton setImage:[UIImage imageNamed:#"iconEditOutlined"] forState:UIControlStateNormal];
[cellOptionsButton setShowsTouchWhenHighlighted:YES];
[cellOptionsButton setAdjustsImageWhenHighlighted:NO];
[cellOptionsButton addTarget:self action:#selector(presentEditView:) forControlEvents:UIControlEventTouchUpInside];
//[cellOptionsContainer addSubview:cellOptionsButton];
[cellOptionsContainer addSubview:cellOptionsButton];
Meanwhile, I was also able to make work the standard edit view in my UITableView delegate (rearranging and deleting both works fine), but I was unable to augment this standard edit view with the added functionality and visual customization illustrated above. I cannot even find a way to change the standard icons...
Any help would be much appreciated; although, I am looking for Objective-C answers as I do not know Swift! I am also doing everything programmatically; I do not use interface builder.

Related

What is the most standard approach to creating a separate menu which can be displayed over a single view controller

Apologize in advance as I'm still new to Xcode.
I have a 2D game build entirely in one viewController. I would like to add both a start menu and in game menu to the game. I assume the best way to do this is through another instance of a viewController? Any advice or suggestions would be very helpful.
First place a UIView on your Xib or UIStoryboard.
Put 2 buttons on it and make their connections and outlets.
The view you want to open is view_Menu.( let us consider)
Now for managing view you need to do this:
view_Menu.frame = CGRectMake(xAxis, yAxis, self.view.frame.size.width, 150);
[self.view addSubView: view_Menu];
In xAxis and yAxis you can put your values.
Now when you click any button inside the menu view you can simply call this method:
[view_Menu RemoveFromSuperview];
So it will help to provide you that you want. A bit of things that you can put a background image or make some custom animations for better look.

Tab Bar controller with code or with template?

I want to create an iOS app which will have use a Tab Bar controller. I know you can set this up by a template within XCode or you can just code it straight, but I'm unclear why use one approach over the other? other than I presume the template allows you to use the interface builder? if I don't want to use interface builder (and I don't) is there any point to using the tab bar app template? can I use the template but remove the interface builder bits? or if I'm doing that I might as well not use the template and just code the controller directly?
As board as the question sounds, let us look at it as a design decision and personal preference.
The Interface Builder allows you to design your layout quickly while providing you the visual bits - you know, how it would look like while designing it.
Can you achieve the same result programmatically? Yes, sure, if you can see it (where the UI element is, the color, the position it has in relation to the other elements, etc etc) while designing in your mind.
Let's say you wanted to have a UIButton, just a button, plain and have it hooked to a method called clicked when pressed. In IB you could achieve that within seconds.
Comparing that to doing it programmatically:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"play a beep" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0f, 80.0f, 40.0f, 40.0f);
[self.view addSubview:button];
You could do it either way - in IB or in code.
For the above case, would doing it in IB faster? Yes. But it doesn't prevent you from also doing it programmatically - it's your preference.
This serves to provide a general answer; because there are many cases involved while designing the interface as to whether one should use IB or do it programmatically.
Can you remove the IB bits? Yes.
Analogy:
Take it as buying a car and pimp it up with fog lamps, have it re-painted etc.
But if you decide to pimp your own ride by replacing every single bits on the car you buy, then why buy a car to do that and not just build one from scratch?

Is it possible to add one UIButton object to multiple UIImageViews?

I have a scrollView and inside this scrollView, there are various PFImageView objects.
I need a single UIButton object on every PFImageView (same place and same button) that will load a subView with the information of the image tapped.
Is this possible?
So, let me get this straight... You want to create only one button, place it on multiple imageViews and have it respond differently (depending on which imageView was tapped)?
In this case...
No, you can't have 1 button in N places.
But... you can create N button objects and have them all assigned to 1 single target method in which... you can have different functionality based on the button's tag.
PS: UICollectionView would be cleaner approach.
You can't have a single control in multiple locations, it's that simple.
I saw your comment about not wanting to use a UICollectionView because it's not the design you're looking for, but I wonder what kind of design you want to create with UIScrollView only because UICollectionView doesn't works.
UICollectionView is not restrained to line/grid display of cells, but can be customized in a huge amounts of ways. You should watch the WWDC 2012 video "Introducing Collection Views" : at the end of it, some UICollectionView possibilities are shown and some of them are quite impressive.
Also, https://www.cocoacontrols.com/ website is a good place to find custom controls and even inspiration for your own design.
This is a little digression from the original issue, but I really think that a collection of UIImageView within an UIScrollView can be created with a UICollectionView, especially if you want to add some controls within your "cells".
Yes. You should use specific control events when adding actions to the button.
E.g. in my application i record/stop/cancel sound as long as user hold a button (drag out to cancel).. like a walkie talkie phone...
[recordButton addTarget:self action:#selector(recordStart) forControlEvents:UIControlEventTouchDown];
[recordButton addTarget:self action:#selector(recordStop) forControlEvents:UIControlEventTouchUpInside];
[recordButton addTarget:self action:#selector(recordCancel) forControlEvents:UIControlEventTouchDragExit];

iOS make button that looks like UINavigationItem

Aside from duplicating the look of UINavigationItem into a custom image file, is there any way to add a button to iOS application that looks like a UINavigationItem?
I have UITableView and would like to have buttons on the right side of each cell for specific actions (1 button per cell, but not all cells have the same buttons). So I was looking to base this on the behaviour of "Delete" button that shows up when doing swipe-to-delete on table cells, except I would also need the ability to change the color and text of such a button.
What's the best way to do something like this?
Edit: I know I can just duplicate that look in Photoshop and use an image, but that way to change title and colour I have to go back to editing the image every time. Is there any way to make a button that looks like UINavigationItem programmatically, outside of a UINavigationBar?
The button style I was looking for is UISegmentedControl. It behaves a little bit different than a standard button, but looks a whole lot better. A good alternative to the ugly inflexible UIButton if you don't have hours to spend making buttons in a graphics editor.
UISegmentedControl *btn = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"My Button"]];
btn.segmentedControlStyle = UISegmentedControlStyleBar;
btn.momentary = YES;
btn.tintColor = [UIColor greenColor];
[btn addTarget:self action:#selector(btn_action:) forControlEvents:UIControlEventValueChanged];

How can I create a dynamic overlay for a UIButton?

My application has a few portions that have really big buttons (640x130, 230x150, etc.) What I need is to have a way to update different portions of the button, with different text. Initially, I assumed that in my code I could create various UILabels and then add them as subviews to my button. However, as soon as I try to add a UILabel to the button as a sub-view, my app crashes.
What is the easiest way to create an overlay for a button, that I can completely layout myself, without preventing button taps from being interested using overlay controls?
I imagine there are multiple ways to solve this problem. However, the best solution for my case should use the fewest lines of code (I have quite a few of these types of buttons) and I'd like to be able to continue using some form of configurable button within IB.
I'm not opposed to subclassing UIButton but, if I do, I would like to be able to use it in IB. I've never created a custom UIView for such a circumstance, so I'd need help defining that type of subclass so that it will work correctly in IB.
You need to add the subview to the containing view - not the button. To ensure that is doesn't interfere with button presses, be sure to set it to:
[myCustomTextOverlay setUserInteractionEnabled:NO];

Resources