Awesome
ACExpandableDescription
ACExpandableDescription is custom iOS control that provides an adaptable view to show a title and a description if provided. The description text is hiden and only shown if the user taps anywhere inside the ACExpandableDescription
.
Provide the ACExpandableDescription
with:
- A Title
- A Title and a Description
- Nothing
Installation and usage
- Copy
ACExpandableDescription.h
andACExpandableDescription.m
to your Xcode project. - Create a new instance of
ACExpandableDescription
with a frame of your choice and add it to the view hierarchy. Or use interface builder to create the view and change the class of that view toACExpandableDescription
. - Set the title and description to the
ACExpandableDescription
object. - Rearrange the views below the
ACExpandableDescription
. The methodgetOriginalSize
will return theCGFrame
of theACExpandableDescription
in the original size so you can relocate the view below it. - Add
Touch Up Inside
event that is going to be called when theACExpandableDescription
is tapped. - Inside the
Touch Up Inside
call rearrange the frame of the views below theACExpandableDescription
. There is a methodheightDifference
that will return afloat
with the distance to move up or down the views.
If you want to change the font to the title or to the description the following methods have to be called with the following NSDictionary
as an argument:
@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:15]};
- (void) setTitleAttributes:(NSDictionary *) attributes
- (void) setDescriptionAttributes:(NSDictionary *) attributes
Examples
If you have title and description provided you just have to set the title and the description to the ACExpandableDescription
. After that you have to rearrange the view below it and set it's frame:
[_expandableView setTitle:@"What do you call a male adult elephant? And an adult female? What about a baby?"];
[_expandableView setDescription:@"Elephants have little in common with cattle, but they share with them the names for adult male (bull), adult female (cow) and juvenile (calf). Even their collective noun is the same: a herd of elephants."];
CGRect frame = [_expandableView getOriginalSize];
[_otherContent setFrame:CGRectMake(_otherContent.frame.origin.x,
frame.origin.y + frame.size.height,
_otherContent.frame.size.width,
_otherContent.frame.size.height)];
- (IBAction)expandStarted:(id)sender {
[UIView animateWithDuration:_expandableView.animationTime animations:^{
[_otherContent setFrame:CGRectMake(_otherContent.frame.origin.x, _otherContent.frame.origin.y + [_expandableView heightDifference], _otherContent.frame.size.width, _otherContent.frame.size.height)];
}];
}
The result will be:
If you have just the title, set the title (and if you want the empty the description) to the ACExpandableDescription
. After that you have to rearrange the views below it:
[_expandableView setTitle:@"What do you call a male adult elephant? And an adult female? What about a baby?"];
CGRect frame = [_expandableView getOriginalSize];
[_otherContent setFrame:CGRectMake(_otherContent.frame.origin.x,
frame.origin.y + frame.size.height,
_otherContent.frame.size.width,
_otherContent.frame.size.height)];
- (IBAction)expandStarted:(id)sender {
[UIView animateWithDuration:_expandableView.animationTime animations:^{
[_otherContent setFrame:CGRectMake(_otherContent.frame.origin.x, _otherContent.frame.origin.y + [_expandableView heightDifference], _otherContent.frame.size.width, _otherContent.frame.size.height)];
}];
}
The result will be:
If you have nothing provided ACExpandableDescription
will return an empty view. Rearrange the views below it:
[_expandableView setTitle:@""];
CGRect frame = [_expandableView getOriginalSize];
[_otherContent setFrame:CGRectMake(_otherContent.frame.origin.x,
frame.origin.y + frame.size.height,
_otherContent.frame.size.width,
_otherContent.frame.size.height)];
- (IBAction)expandStarted:(id)sender {
[UIView animateWithDuration:_expandableView.animationTime animations:^{
[_otherContent setFrame:CGRectMake(_otherContent.frame.origin.x, _otherContent.frame.origin.y + [_expandableView heightDifference], _otherContent.frame.size.width, _otherContent.frame.size.height)];
}];
}
The result will be:
Version
1.0
License
MIT
Free Software, Hell Yeah!