Comments (1)
Not sure of the elegance of the solution I thought of two solutions that ideally would work without having to subclass UILabel
- inset both sides of the label by image width
- ignore image width if text is centered
Not sure how viable they are or if they're even really worth doing, however i threw option 2 in the test project and it seems to work. I just modified CRToast -layoutSubview
specifically lines 1053-1088 hold all the changes.
CGFloat titleLabelX = (imageSize.width == 0 || self.toast.textAlignment == NSTextAlignmentCenter) ? kCRStatusBarViewNoImageLeftContentInset : CGRectGetMaxX(_imageView.frame);
CGFloat subTitleLabelX = (imageSize.width == 0 || self.toast.subtitleTextAlignment == NSTextAlignmentCenter) ? kCRStatusBarViewNoImageLeftContentInset : CGRectGetMaxX(_imageView.frame);
CGFloat x = imageSize.width == 0 ? kCRStatusBarViewNoImageLeftContentInset : CGRectGetMaxX(_imageView.frame);
CGFloat width = CGRectGetWidth(contentFrame)-x-kCRStatusBarViewNoImageRightContentInset;
if (self.toast.subtitleText == nil) {
self.label.frame = CGRectMake(titleLabelX,
statusBarYOffset,
width,
CGRectGetHeight(contentFrame));
} else {
CGFloat height = MIN([self.toast.text boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : self.toast.font}
context:nil].size.height,
CGRectGetHeight(contentFrame));
CGFloat subtitleHeight = [self.toast.subtitleText boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : self.toast.subtitleFont }
context:nil].size.height;
if ((CGRectGetHeight(contentFrame) - (height + subtitleHeight)) < 5) {
subtitleHeight = (CGRectGetHeight(contentFrame) - (height))-10;
}
CGFloat offset = (CGRectGetHeight(contentFrame) - (height + subtitleHeight))/2;
self.label.frame = CGRectMake(titleLabelX,
offset+statusBarYOffset,
CGRectGetWidth(contentFrame)-titleLabelX-kCRStatusBarViewNoImageRightContentInset,
height);
self.subtitleLabel.frame = CGRectMake(subTitleLabelX,
height+offset+statusBarYOffset,
CGRectGetWidth(contentFrame)-subTitleLabelX-kCRStatusBarViewNoImageRightContentInset,
subtitleHeight);
}
There's probably a better way but ¯\_(ツ)_/¯
from crtoast.
Related Issues (20)
- Xcode 8 and failed to render issue
- Xcode 8 compilation issues
- kCRToastTimeIntervalKey issue with Xcode 8.1 swift 3 HOT 4
- CRToastInteractionResponder crash HOT 4
- Crashes when creating larger toaster HOT 1
- Custom height issue on Swift 3 HOT 1
- Displaying notification while in landscape mode bugged
- CRToast should build without warnings HOT 2
- Toast won't disappear on ios 11 HOT 6
- Can show from nav bar bottom?
- Can't set custom notification height in Swift 3 HOT 1
- Whether to support clicking on the outside of the toast to make it disappear?
- Please Disable Code Coverage HOT 1
- Status bar text ( center aligned) doesn't show up in iPhone X HOT 9
- Space between title and subtitle when subtitle is long
- If text is too long, how to fix that? HOT 2
- cleanup warnings
- Solved: Subtitle text not showing
- imkageKey
- Error in Xcode 15.3 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crtoast.