Can a standard accessory view be in a different position within a UITableViewCell?
No, you cannot move where the accessory view is. As an alternative you can add a subview like the following;
[cell.contentView addSubview:aView];
Also, by setting the accessoryView
property equal to something, the accessoryType
value is ignored.
How to override accessoryView in UITableViewCell to change it's position
Based on Matt's tip the only way I found to do this was to just use my own UIImageView
and use the image of my choice and then set the frame
coordinates to what I needed. This allowed the accessoryView
to expand. Apparently this is the only way to manipulate it.
UIImage *indicatorImage = [UIImage imageNamed:@"BV-icon_57x57"];
UIImageView *view = [[UIImageView alloc] initWithImage:indicatorImage];
view.frame = CGRectMake(0, 0, 100, 20);
[view setContentMode:UIViewContentModeLeft];//without this line the image will just be stretched;
cell.accessoryView = view;
Vertical center on UITableViewCell accessoryView's element
You cannot change the position of a accessoryView
. Please refer to the following question:
Can a standard accessory view be in a different position within a UITableViewCell?
It is okay for you to apply transformation such as scale, and rotation to the accessory view. However, you are not able to apply translate transformation to the accessory view. For example,
switchView.transform = CGAffineTransformTranslate(CGAffineTransformMakeScale(0.5, 0.5),10,10);
Only the scale part of the transformation is applied to the switchView
. Looking through the apple documentation, I also found this following line of note:
... The accessory view appears in the right side of the cell.
I don't think apple do want you to customized the location of the accessory view. Based on your question, I also tried changing the centre and the frame of the accessoryView, I do notice that the position of the accessoryView is not moving at all.
In short, If you really want to change the size of the UISwitch
and move it to the vertical align it in the table view cell, I think you have only one option: You will have to add UISwitch
as a subview of the cell and then you will have to freedom to do whatever you want.
UITableViewCell accessoryType position change with cell height
I think the accessoryView is positioned so that the distance from the right, top, and bottom edges is correlated in some way, so you have to reposition it.
Probably the best way is to subclass UITableViewCell, and override the layoutSubviews method:
- (void)layoutSubviews {
[super layoutSubviews];
CGRect accessoryFrame = self.accessoryView.frame;
accessoryFrame.origin.x = <desired position here>;
self.accessoryView.frame = accessoryFrame;
}
set position of uitableviewcellaccessory
Set the accessoryView initial frame is affectless, it is changed any time that the cell does a layout, you need to:
- (void)layoutSubviews
{
[super layoutSubviews];
self.accessoryView.center = CGPointMake($yourX, $yourY);
}
This is a simple way to set a custom position for the accessoryView that is persisted in any cell status
How to get frame of accessoryView frame in tableview cell ios swift
If you are using custom accessory view set via the cell's accessoryView
property, you can get its frame using this same property. However, if you use the default accessory set via accessoryType
, there's no built-in way to get its frame, but only by iterating over the cell's subviews and finding it there, it should be of UIButton
class.
I'd suggest using a custom accessory view and getting its frame using the documented methods which should be safer.
Align UITableViewCell accessoryView to bottom of cell instead of middle
I found that you can subclass UITableViewCell, override layoutSubviews, and in that method, get the accessoryView and adjust its frame as desired.
Related Topics
Ios7 Safari: Saving to Home-Screen and Persist Token
Reading Long Characteristic Values Using Corebluetooth
Editing Screenshots in Itunes Connect After iOS App Was Approved
How to Calculate the Height of an Nsattributedstring with Given Width in iOS 6
Change the Font Size of Uisearchbar
How to Define the Size of a Collectionview on Rotate
Does Firebase Cloud Messaging Support Voip Pushkit Services
Objc_Sync_Enter/Objc_Sync_Exit Not Working with Dispatch_Queue_Priority_Low
Show Uipickerview Text Field Is Selected, Then Hide After Selected
Uiwebview Random Crash at [Uiviewanimationstate Release]: Message Sent to Deallocated Instance
How to Use Avsamplebufferdisplaylayer in iOS 8 for Rtp H264 Streams with Gstreamer
Avplayer Stops Playing Video After Buffering
Xcode 7 How to Refresh Provisioning Profiles
Xcode: Could Not Inspect the Application Package
Use Uibarbuttonitem Icon in Uibutton
Showing a Uipickerview with Uiactionsheet in iOS8 Not Working
How to Hide First Section Header in Uitableview (Grouped Style)