Closed EddieLukeAtmey closed 7 years ago
Hello @EddieLukeAtmey, I'll check the issue and will let you know of the fix.
@EddieLukeAtmey I tried to reproduce your issue but all separator colors in the Example project are displayed correctly, as well as no issues with truncated label. Could you provide more details on your setup?
@maxkonovalov I subclass your control and customize it to fit my stuff:
@interface MyDropDownMenu : MKDropdownMenu
/*! Attributed String Dictionary for Normal text. */
@property (strong, nonatomic) NSDictionary *attributeString;
@end
And then I have some stuff when initialze control (call in initWith...:
and awakeFromNib
). Currently I don't use separatorColor
yet. That day I just found out the property and try it out to see how it work.
- (void)setupDropDown
{
// Setup dropdown
self.dropdownDropsShadow = NO;
self.dataSource = self;
self.delegate = self;
self.backgroundDimmingOpacity = 0;
self.dropdownBouncesScroll = NO;
self.disclosureIndicatorImage = [UIImage imageNamed:@"ic_expand"];
// setup later.
self.selectedDatas = @[];
self.selectedIndexes = @[];
}
And then stuff for selected row
- (NSDictionary *)selectedAttributeString { return _selectedAttributeString ?: self.attributeString; }
- (void)setAttributeString:(NSDictionary *)attributeString
{
_attributeString = attributeString;
// Make selected font bolder
if (attributeString[NSFontAttributeName]) {
UIFont *font = attributeString[NSFontAttributeName];
UIFont *selectedFont = [UIFont fontWithDescriptor:[[font fontDescriptor] fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]
size:font.pointSize + 2];
if (selectedFont) {
NSMutableDictionary *selectedAttribute = [attributeString mutableCopy];
[selectedAttribute setObject:selectedFont forKey:NSFontAttributeName];
self.selectedAttributeString = selectedAttribute;
}
}
}
- (NSAttributedString *)dropdownMenu:(MKDropdownMenu *)dropdownMenu attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *data = self.dataList[row];
NSDictionary *attribute = [self.selectedDatas containsObject:data] ? self.selectedAttributeString : self.attributeString;
NSAttributedString *value = [[NSAttributedString alloc] initWithString:data
attributes:attribute];
return value;
}
Other stuffs
- (NSInteger)dropdownMenu:(MKDropdownMenu *)dropdownMenu numberOfRowsInComponent:(NSInteger)component { return self.dataList.count; }
- ( CGFloat )dropdownMenu:(MKDropdownMenu *)dropdownMenu rowHeightForComponent:(NSInteger)component { return self.frame.size.height; }
- (UIColor *)dropdownMenu:(MKDropdownMenu *)dropdownMenu
backgroundColorForRow:(NSInteger)row forComponent:(NSInteger)component { return self.backgroundColor; }
Update: I've tried comment out all those attributedString, event replace the protocol impl to the basic one titleForRow:inComponent:
. Still the same. Probably not because of attributedString
I tried to replicate your setup - still no issues. Are you sure you don't set layer.borderColor
or something similar manually in your code?
You can try commenting out more parts of your subclass code until the issue goes away to identify the problem.
Okay, so I've commented out almost every customized stuff. Everything went back to normal. But once I set self.dropdownShowsBorder = NO
the label is truncated (separator still working fine). And that's really the cause for the issue (refer to the origin question).
Check images below, the width of the label is 15, which is why it's truncated. Reason related to separator inset.
I'll check again how to reproduce the issue with separator border.
Great! We're getting closer :) It's really strange that table view cell separator affects the content...
I think it might be related to the layout margins somehow.
Can you try adding this line:
cell.preservesSuperviewLayoutMargins = NO;
to the -tableView:cellForRowAtIndexPath:
in MKDropdownMenu.m
line 754, just after cell.layoutMargins = UIEdgeInsetsZero;
Also can try to add:
self.tableView.layoutMargins = UIEdgeInsetsZero;
@EddieLukeAtmey let me know if the above changes anything. If not, we should keep commenting out the code to find the reason of the issue :)
Alright, I've try adding cell.preservesSuperviewLayoutMargins = NO;
in the line you suggest, not working.
About self.tableView.layoutMargins = UIEdgeInsetsZero
, you've already set it in viewDidLoad (Line 419)
I see... So the only thing is to keep searching for the cause of this now
As you commented the rejection of the #18 pull request, about the last row separator, how about we try using this solution:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1)];
Ok, I updated the bottom row separator logic to use footer view - see bb021f60825c40507338deb34670d63a72ac20bd
For my issue, your fix works like a charm
But it seems that solution didn't solve the last line separator
I think it should be like this
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
Also, I have to specify your commit to pod file instead of general pod:
pod 'MKDropdownMenu', :git => 'https://github.com/maxkonovalov/MKDropdownMenu.git', :commit => 'bb021f6'
Can you please check the example project - the fix works fine there.
Also, you need to set dropdownShowsBottomRowSeparator = NO
because it's enabled by default.
Work like a charm! Thank you very much!!!
@EddieLukeAtmey you're welcome :) The changes are now available in cocoapods 🎉
Hi, the border (in #6) works pretty fine, except that something with
dropdownShowsBorder == YES
in line 752~756:I'm not sure why you have to set
seperatorInset
to the last row when showing border, but it seems to crop the data inside the cell and my label turn from any to "..." string. I've tried comment out everything exceptcell.separatorInset = UIEdgeInsetsZero;
and it turns out fine.Also, there seems to have a problem with
rowSeparatorColor
, as it affect the border color but doesn't to the seperator (image below).Though I agree that the border color should be the same as the separator's, please do something with these, thanks!!! (I was checking in ios 10.2)